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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Codeforces Round #657 (Div. 2)

發布時間:2023/12/3 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #657 (Div. 2) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A. Acacius and String

爆零!太菜了,下來終于把A題代碼調AC了

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<iostream> #include<algorithm> #include<cstring> #include<string> using namespace std; int n; string res="abacaba"; int main() {IO;int T;cin>>T;while(T--){cin>>n;string s;cin>>s;int flag=0;for(int i=0;i+6<n;i++)if(s.substr(i,7)==res) flag++;if(flag>1) cout<<"No"<<endl;else if(flag==1){cout<<"Yes"<<endl;for(auto t:s){if(t=='?') cout<<'e';else cout<<t;}cout<<endl;}else{for(int i=0,j=0;i<n;i++){if(s[i]=='?'||s[i]==res[j]){j++;if(j==7){if((i+4<n&&"aba"+s.substr(i+1,4)==res)||(i>=10&&s.substr(i-10,4)+"aba"==res)){j=0;i=i-6;}else {for(int x=i-6,y=0;y<7;x++,y++) s[x]=res[y];break;}}}else{i=i-j;j=0;}}for(int i=0;i+6<n;i++)if(s.substr(i,7)==res) flag++;if(flag>1) cout<<"No"<<endl;else if(flag==1){cout<<"Yes"<<endl;for(auto t:s){if(t=='?') cout<<'e';else cout<<t;}cout<<endl;}else cout<<"No"<<endl;}}return 0; }

B. Dubious Cyrpto

賽后補題瞎搞,直接AC了自己都很迷
na+b?c=mna+b-c=mna+b?c=m稍微化簡一下na=m+c?bna=m+c-bna=m+c?b,然后對于右邊一項的范圍是[m+l?r,m?l+r][m+l-r,m-l+r][m+l?r,m?l+r],即代碼中的[lmin,lmax],然后枚舉a,考慮lmina\frac{lmin}{a}almin?lmaxa\frac{lmax}{a}almax?,如果lmina<lmaxa\frac{lmin}{a} < \frac{lmax}{a}almin?<almax?,那么由于下取整,lmaxa\frac{lmax}{a}almax?肯定能夠整除aaa,如果lmina=lmaxa\frac{lmin}{a}=\frac{lmax}{a}almin?=almax?,考慮他倆之間是否有能夠整除aaa的即可,其他情況均不能整除aaa,然后就可以知道c?bc-bc?b的差na?mna-mna?m,然后枚舉bbb,求個在范圍中的ccc輸出即可

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<iostream> #include<algorithm> using namespace std; typedef long long ll; ll l,r,m; int main() {IO;int T;cin>>T;while(T--){cin>>l>>r>>m;ll lmin=m+l-r,lmax=m+r-l;ll n=-1,b=-1,c=-1,x=r;int a;for(a=l;a<=r;a++){if(lmin/a<lmax/a){n=lmax/a;x=a*n-m;break;}else{if(lmin%a==0){n=lmin/a;x=a*n-m;break;}else if(lmax%a==0){n=lmax/a;x=a*n-m;break;}}}for(int b=l;b<=r;b++){if(x+b>=l&&x+b<=r){cout<<a<<" "<<b<<" "<<x+b<<endl;break;}}}return 0; }

C. Choosing flowers

貪心+枚舉+二分
首先容易證明最優解肯定只選擇一種花多次(貪心),然后先對flower[i].a降序排列,枚舉最終選擇哪一種花多次,不妨假設最后選flower[i]多次,對于其他花的a如果大于flower[i].b肯定是需要選上,因此可以二分邊界,然后分類一下就可以了。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<iostream> #include<algorithm> #define a first #define b second using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N=100010; pii flower[N]; int n,m; ll s[N]; int main() {IO;int T;cin>>T;while(T--){cin>>m>>n;for(int i=1;i<=n;i++) cin>>flower[i].a>>flower[i].b;sort(flower+1,flower+1+n);reverse(flower+1,flower+1+n);for(int i=1;i<=n;i++) s[i]=s[i-1]+1ll*flower[i].a;ll res=0;for(int i=1;i<=n;i++){int l=0,r=n;//注意邊界l=0,如果所有flower的a值都小于枚舉的b值最終應該是0while(l<r){int mid=l+r+1>>1;if(flower[mid].a>flower[i].b) l=mid;else r=mid-1;}if(m<=l) res=max(res,s[m]);else{if(i<=l) res=max(res,s[l]+1ll*flower[i].b*(m-l));else res=max(res,s[l]+1ll*flower[i].a+1ll*flower[i].b*(m-l-1));}}cout<<res<<endl;}return 0; }

希望今天的div2不爆零,要加油哦!

總結

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

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