赞
踩
int main() { ios; int t; cin >> t; while (t--) { ll p,a,b,c; cin >> p >> a >> b >> c; ll t1=p/a+(p%a==0?0:1); ll t2=p/b+(p%b==0?0:1); ll t3=p/c+(p%c==0?0:1); t1=t1*a-p; t2=t2*b-p; t3=t3*c-p; cout << min(t1,min(t2,t3)) << endl; } }
int p[maxn]; map<int,int> book; int main() { ios; int t; cin >> t; while (t--) { book.clear(); int n; cin >> n; int maxx=-1; for(int i=1;i<=n;i++) { cin >> p[i]; book[p[i]]=i; } int pre=n+1,num=0; for(int i=n;i>=1;i--) { if(book[i]>pre) continue; for(int j=book[i];j<pre;j++) cout << p[j] << ' '; num+=pre-book[i]; if(num==n) break; pre=book[i]; } cout << endl; } }
正向和逆向都找一遍,取第一个符合条件的字符串,做差找最大值即可。
char s[maxn],t[maxn]; int p1[maxn],p2[maxn]; int m,n; void solve() { for(int i=1,j=1;i<=n && j<=m;i++) if(s[i]==t[j]) p1[j++]=i; for(int i=n,j=m;i>=1 && j>=1;i--) if(s[i]==t[j]) p2[j--]=i; int ans=1; for(int i=2;i<=m;i++) ans=max(ans,p2[i]-p1[i-1]); cout << ans << endl; } int main() { cin >> n >> m; scanf("%s%s",s+1,t+1); int pos=1; solve(); }
构造,10-01=01,100-001=011,这样我们可以构造任意数量的1。
根据这个去模拟构造即可。
int main() { ios; int a,b,k,aa,bb; cin >> a >> b >> k; aa=a,bb=b; if(b==1) { if(k==0) { cout << "YES" << endl; cout << 1; for(int i=1;i<a+b;i++) cout << 0; cout << endl; cout << 1; for(int i=1;i<a+b;i++) cout << 0; cout << endl; } else cout << "NO" << endl; } else if(k>a+b-2) cout << "NO" << endl; else { string s1="",s2=""; if(k!=0) { s1="11"; s2="10"; b-=2; for(int i=1;i<k;i++) { if(a>1) { a--; s1+="0"; s2+="0"; } else { b--; s1+="1"; s2+="1"; } } s1+="0"; s2+="1"; a-=1; } for(int i=1;i<=b;i++) { s1+="1"; s2+="1"; } for(int i=1;i<=a;i++) { s1+="0"; s2+="0"; } int num0=0,num1=0; for(int i=0;i<s1.length();i++) { if(s1[i]=='1') num1++; else num0++; } if(num1!=bb || num0!=aa) { cout << "NO" << endl; return 0; } cout << "YES" << endl; cout << s1 << endl; cout << s2 << endl; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。