Codeforces Round 834 (Div. 3)
思路:判断每种情况即可
#include<bits/stdc++.h> using namespace std; //#define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=2e6+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve() { string s;cin>>s; char p; for(int i=0;i<s.size();++i){ if(i==0){ p=s[i]; if(s[i]!='Y'&&s[i]!='e'&&s[i]!='s'){ cout<<"NO\n";return ; } continue; } if(p=='Y'&&s[i]!='e'){ cout<<"NO\n";return ; }if(p=='e'&&s[i]!='s'){ cout<<"NO\n";return ; }if(p=='s'&&s[i]!='Y'){ cout<<"NO\n";return ; } p=s[i]; } cout<<"YES\n"; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T=1; cin>>T; // init(); while(T--){ solve(); } return 0; }View Code
思路:将排序填满,看是否用完m
#include<bits/stdc++.h> using namespace std; //#define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=2e6+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve() { int m,s;cin>>m>>s; vector<int>ve(1000); int ma=0; for(int i=0;i<m;++i){ int x;cin>>x; ve[x]=1;ma=max(ma,x); } for(int i=1;s>0;++i){ if(ve[i])continue; s-=i; ve[i]=1;ma=max(ma,i); } if(s==0){ for(int i=1;i<=ma;++i) if(!ve[i]){ cout<<"NO\n";return ; } cout<<"YES\n"; } else cout<<"NO\n"; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T=1; cin>>T; // init(); while(T--){ solve(); } return 0; }View Code
思路:分情况讨论,1.1次:a→b
2.2次:a→l→b或a→r→b(a<b),a>b同理
3.3次:a→r→l→b(a<b),a>b同理
4.0次:a=b
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve() { int l,r,x,a,b; cin>>l>>r>>x>>a>>b; if(a==b){ cout<<"0\n";return ; } if(abs(a-b)>=x){ cout<<"1\n";return ; } if(abs(l-a)<x&&abs(r-a)<x){ cout<<"-1\n";return ; } if(abs(l-b)<x&&abs(r-b)<x){ cout<<"-1\n";return ; } if(a<b){ if(abs(l-a)>=x)cout<<2<<'\n'; else if(abs(r-b)>=x)cout<<2<<'\n'; else cout<<3<<'\n'; }else{ if(abs(r-a)>=x)cout<<"2\n"; else if(abs(l-b)>=x)cout<<"2\n"; else cout<<3<<'\n'; } } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T=1; cin>>T; // init(); while(T--){ solve(); } return 0; }View Code
思路:n=k*2a*5b,让a和b的数目先相同,再同时都增加,直到不能加为止,再乘上2~9中满足小于等于m的数
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=5e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ int n,m;cin>>n>>m; int cnt2=0,cnt5=0,nn=n; while(nn&&nn%2==0){ cnt2++;nn/=2; } while(nn&&nn%5==0){ cnt5++;nn/=5; } int ad=1; while(cnt2<cnt5){ if(ad*2>m)break; ad*=2;cnt2++; } while(cnt2>cnt5){ if(ad*5>m)break; ad*=5;cnt5++; } while(ad*10<=m){ ad*=10; } // cout<<ad<<' '; cout<<m/ad*n*ad<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; cin>>t; while(t--){ solve(); } return 0; }View Code
思路:当前h越大,使用药水后的h一定更大;所以先吸收能吸收的人,直到不能吸收后再用药水,由于药水只有三个,枚举每一种情况取最大值即可
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=5e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ int n,h;cin>>n>>h; vector<int>f={2,2,3,2,2}; vector<int>ve(n); for(int i=0;i<n;++i)cin>>ve[i]; sort(ve.begin(),ve.end()); int ans=0; auto get=[n,h,ve,f](int x){ int cnt=0,hh=h,r=x; for(int i=0;i<n;++i){ if(hh>ve[i])hh+=ve[i]/2,cnt++; else{ if(r-x>=3)break; hh*=f[r++]; i--; } } return cnt; }; for(int i=0;i<3;++i){ ans=max(ans,get(i)); } cout<<ans<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; cin>>t; while(t--){ solve(); } return 0; }View Code
思路:每次操作加一,不用进位就能完成的情况:没写的最小的数大于最后一位;
需要进位:没写的最小的数小于最后一位;需要模拟出进一次位的过程,之后再找到没写的最大的数即是最后要操作到的数
由于最多有100位,那么写了的数初始最多有100个,暴力找没写的极值数即可
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve() { int n,p;cin>>n>>p; vector<int>ve(n+5); set<int>se; int ans=0; for(int i=n-1;i>=0;--i)cin>>ve[i],se.insert(ve[i]); if(se.size()==p){ cout<<"0\n";return ; } int tr=-1,tl=-1; for(int i=p-1;i>=0;--i){ if(!se.count(i)){ tr=i;break; } } for(int i=0;i<p;++i){ if(!se.count(i)){ tl=i;break; } } if(tl>ve[0]){ cout<<tr-ve[0]<<'\n';return ; } ans+=p-1-ve[0]; //ve[0]=0; se.insert(0); ve[1]++;ans++; if(n==1)n++; for(int i=1;i<n;++i){ if(ve[i]>=p){ ve[i]-=p,se.insert(ve[i]),ve[i+1]++; if(i==n-1)se.insert(ve[n]); } else{ se.insert(ve[i]); break; } } tr=0; for(int i=ve[0];i>=0;--i){ if(!se.count(i)){ tr=i;break; } } ans+=tr; cout<<ans<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T=1; cin>>T; // init(); while(T--){ solve(); } return 0; }View Code
思路:要满足字典序最小,且偶数位的数已确定,正着找小于该数的数会考虑很多情况,可以倒着找,对于一个偶数位的数,找到小于它的最大的数为最优的情况,若存在多个偶数位,靠后的先选,用优先队列维护
#include<bits/stdc++.h> using namespace std; //#define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; int n; void solve() { cin>>n; vector<int>ve(n+1),pos(n+1); for(int i=2;i<=n;i+=2){ cin>>ve[i];pos[ve[i]]=i; } priority_queue<int>q; for(int i=n;i>=1;--i){ if(pos[i])q.push(pos[i]); else{ if(q.empty()){ cout<<"-1\n";return ; } ve[q.top()-1]=i;q.pop(); } } for(int i=1;i<=n;++i)cout<<ve[i]<<' ';cout<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T=1; cin>>T; // init(); while(T--){ solve(); } return 0; }View Code
标签:typedef,ve,834,int,double,Codeforces,long,Div,define From: https://www.cnblogs.com/bible-/p/17756656.html