Educational Codeforces Round 117 (Rated for Div. 2)
A. Distance
B. Special Permutation
C. Chat Ban
D.X-Magic Pair
E. Messages
F:沒看F,好難的樣子
G. Max Sum Array
硬模擬
#include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <cmath> #include <stack> #include <map> #define mid (l+r>>1) #define lowbit(x) (x&-x) using namespace std; typedef long long LL; typedef pair<int,int> PII; const int N = 1e5, M = 5e2;int main() {int t;scanf("%d", &t);while(t --){int n, a, b, l = 1, r = 2, pos[N]={0}, nl = 0, nr = 0;bool f = 0;scanf("%d%d%d", &n, &a, &b);for(int i = n;i > b;i --)pos[i] = l, nl++;if(!pos[a])pos[a] = l, nl++;for(int i = 1;i < a;i ++)f |= pos[i] == l, pos[i] = r, nr++;if(!pos[b]) f |= pos[b] == l, pos[b] = r, nr++;for(int i = a+1;i < b;i ++)if(!pos[i]){if(nl < n/2)pos[i] = l, nl++;else pos[i] = r;}if(f || nl!=n/2)puts("-1");else{for(int i = 1;i <= n;i ++)if(pos[i] == l)cout<<i<<' ';for(int i = 1;i <= n;i ++)if(pos[i] == r)cout<<i<<' ';puts("");}}return 0; }二分直接算
#include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <cmath> #include <stack> #include <map> #define mid (l+r>>1) #define lowbit(x) (x&-x) using namespace std; typedef long long LL; typedef pair<int,int> PII; const int N = 1e5, M = 5e2;LL k, x;bool ch(LL l) {LL sum = 0;if(l>k) sum = (1+k)*k/2 + (k+2*k-l-1)*(l-k)/2;else sum = (1+l)*l/2;return sum>=x; } int main() {int t;scanf("%d", &t);while(t --){scanf("%lld%lld", &k, &x);LL l = 1, r = 2*k-1;while(l < r){if(ch(mid)) r=mid;else l=mid+1;}cout<<l<<endl;}return 0; }隊(duì)友寫的,沒搞懂
#include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <cmath> #include <stack> #include <map> #define mid (l+r>>1) #define lowbit(x) (x&-x) using namespace std; typedef long long LL; typedef pair<int,int> PII; const int N = 1e5, M = 5e2;int main() {int t;scanf("%d", &t);while(t --){LL a, b, x;bool f = 0;scanf("%lld%lld%lld", &a, &b, &x);if(x<=max(a, b)){while(a>=x||b>=x&&a&&b){if(a<b)swap(a, b);if(a==x||b==x||(a-x)%b==0){f = 1;break;}a %= b;}}puts(f?"YES":"NO");}return 0; }?概率公式計(jì)算,假設(shè)有n張牌,其中里面有他要的,它可以抽k張牌,如果k>n那么這個(gè)人的期望就是n/n,否則是1 - (n?1k)\tbinom{n-1}{k}(kn?1?)/(nk)\tbinom{n}{k}(kn?) = k / n。
?然后可以枚舉小于20的n枚舉的時(shí)候k大于n的貢獻(xiàn)要變成1。
?對于大于20的n來說答案就可以按照期望貢獻(xiàn)對數(shù)字排序,再進(jìn)行遞推枚舉計(jì)算。
具體看代碼
? 沒人補(bǔ)G嗎,假設(shè)有n個(gè)相等數(shù)字且位置為P1 P2 P3 …Pn,那么你計(jì)算之后就可以得到 ∑i=1n\sum_{i=1}^n∑i=1n? ( 2 ?\ast? i - n -1) ?\ast? Pi
? 那么再對于每個(gè)n都確定前面的 ( 2 ?\ast? i - n -1),那么這個(gè)東西就由 Pi 確定,然后可以看出( 2 ?\ast? i - n -1)要么都是奇數(shù)要么都是偶數(shù)那么再把不連續(xù)的變成連續(xù)的(這步在代碼里面有注釋), 再挨個(gè)計(jì)算,數(shù)量就是( 2 ?\ast? i - n -1)相等的數(shù)量的階乘的乘積
#include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <cmath> #include <stack> #include <set> #define mid (l+r>>1) #define lowbit(x) (x&-x) using namespace std; typedef long long LL; typedef pair<int,int> PII; const int N = 2e6+10, mod = 1e9 + 7; void mull(int &a, LL b){a = a*b%mod;return ;} void add(int &a, LL b){a = (a+b)%mod;return ;}LL a[N], b[N], in[N]; // a :-2 0 2 4 6 -> -1 0 1 2 3 n 是奇數(shù) // b :-3 -1 1 3 -> -2 0 2 4 < a n 是偶數(shù) LL se(LL a, int b){a%=mod;return b*(a+a+b-1)%mod*500000004%mod;}int main() {int n;scanf("%d", &n);in[0] = 1;for(int i = 1;i <= n;i ++){int x;scanf("%d", &x);LL *t = a, f = 0;if(x%2 == 0)t = b, f = 1;t[(1-x+f)/2+(int)1e6]++;t[(x-1+f)/2+(int)1e6+1]--;in[i] = i*in[i-1]%mod;}int ans = 0, sum = 1;LL head = 1;for(int i = 0;i <= 2e6;i ++){a[i] += a[i-1]; b[i] += b[i-1];add(ans, ((i-(int)1e6)*2-1)*se(head, b[i])%mod);head += b[i];add(ans, ((i-(int)1e6)*2)*se(head, a[i])%mod);head += a[i];mull(sum, in[b[i]]*in[a[i]]%mod);}add(ans, mod);cout<<ans<<' '<<sum<<endl;return 0; }總結(jié)
以上是生活随笔為你收集整理的Educational Codeforces Round 117 (Rated for Div. 2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: graphql_普通英语GraphQL指
- 下一篇: 程序员表白、恶搞代码 VBS 系统内置脚