日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Educational Codeforces Round 117 (Rated for Div. 2)

發布時間:2023/12/3 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 a, b;scanf("%d%d", &a, &b);if(abs(a)+abs(b)&1)puts("-1 -1");else{int x = abs(a)>>1, y = (abs(a)+abs(b)>>1)-x;if(a<0)x=-x;if(b<0)y=-y;cout<<x<<' '<<y<<endl;}}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;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; }

隊友寫的,沒搞懂

#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; }

?概率公式計算,假設有n張牌,其中里面有他要的,它可以抽k張牌,如果k>n那么這個人的期望就是n/n,否則是1 - (n?1k)\tbinom{n-1}{k}(kn?1?)/(nk)\tbinom{n}{k}(kn?) = k / n。
?然后可以枚舉小于20的n枚舉的時候k大于n的貢獻要變成1。
?對于大于20的n來說答案就可以按照期望貢獻對數字排序,再進行遞推枚舉計算。
具體看代碼

#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 = 2e5+10, M = 5e2;int a[N][21]; PII b[N]; vector<int>ans;int main() {int n;scanf("%d", &n);for(int i = 1;i <= n;i ++){int x, y;scanf("%d%d", &x, &y);a[x][y]++; //有個 數字為x,k等于y的人 }LL ma = 0, mn = 1; // ma 是最大值, mn是最大值個數其實在ans-vector里有體現; for(int i = 1;i <= 20;i ++){ // 枚舉n for(int j = 1;j <= 2e5;j ++){ // 遍歷每個樹 int sum = 0; // 當n等于i時數字i對于期望的貢獻 for(int k = 1;k <= i;k ++)sum += a[j][k]*k; // k < n時 k = k, k ≥n時 k = n; for(int k = i+1;k <= 20;k ++)sum += a[j][k]*i;b[j] = {-sum, j}; // 第一關鍵字取反按照從小往大排序的話第一個取反就是最大值; }sort(b+1, b+(int)2e5+1); LL sum = 0;for(int x = 1;x <= i;x ++)sum += -b[x].first;if(sum*mn>ma*i){ // 分式化乘法 ans.clear();for(int x = 1;x <= i;x ++)ans.push_back(b[x].second);ma = sum; mn = i;} }LL h = 0;for(int i = 1;i <= 20&&i <= n;i ++)h += -b[i].first; // 這時候是先求出前二十個的和; for(int i = 21;i <= n;i ++) // 枚舉21 - n 的個數取值; {h += -b[i].first;if(h*mn>ma*i)ma = h, mn = i;}if(mn > 20)for(int i = 1;i <= mn;i ++)ans.push_back(b[i].second);cout<<ans.size()<<endl;for(auto x: ans)cout<<x<<' ';cout<<endl;return 0; }

? 沒人補G嗎,假設有n個相等數字且位置為P1 P2 P3 …Pn,那么你計算之后就可以得到 ∑i=1n\sum_{i=1}^ni=1n? ( 2 ?\ast? i - n -1) ?\ast? Pi

? 那么再對于每個n都確定前面的 ( 2 ?\ast? i - n -1),那么這個東西就由 Pi 確定,然后可以看出( 2 ?\ast? i - n -1)要么都是奇數要么都是偶數那么再把不連續的變成連續的(這步在代碼里面有注釋), 再挨個計算,數量就是( 2 ?\ast? i - n -1)相等的數量的階乘的乘積

#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 是奇數 // b :-3 -1 1 3 -> -2 0 2 4 < a n 是偶數 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; }

總結

以上是生活随笔為你收集整理的Educational Codeforces Round 117 (Rated for Div. 2)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。