标签:memset sizeof show gre ref turn hide cdc color
#include<bits/stdc++.h> using namespace std; int main(){ int n1,p1,s1,n2,p2,s2; cin>>n1>>p1>>s1; cin>>n2>>p2>>s2; if(n1!=n2){ if(n1>n2)cout<<"1\n"; else cout<<"2\n"; return 0; } if(p1!=p2){ if(p1<p2)cout<<"1\n"; else cout<<"2\n"; return 0; } if(s1!=s2){ if(s1<s2)cout<<"1\n"; else cout<<"2\n"; return 0; } cout<<"God\n"; return 0; }
B:Number
#include<bits/stdc++.h> using namespace std; int t,n; int main(){ scanf("%d",&t); while(t--){ int ans=0; scanf("%d",&n); while(n>1){ int p=n%10; if(p==0){ ans++; n/=10; } else{ n=n+10-p; ans=ans+10-p; } } printf("%d\n",ans); } return 0; }
(a*k+1)3=a3*k3+3a2k2+3ak+1=(a2*k3+3a1k2+3k)a+1=a*x+1;
即(a*k+1)的3次方也是a的倍数+1;
#include<bits/stdc++.h> using namespace std; int t,l,r; int main(){ scanf("%d",&t); while(t--){ long long ans=0; scanf("%d%d",&l,&r); int p=l/192,q=r/192; if(l%192>1)p++; if(r%192<1)q--; for(int i=p;i<=q;i++){ ans=ans+(long long )i*192+1; } printf("%lld\n",ans); } return 0; }
D:Stone
每次取最大堆与任一相邻合并,结果 : 总和-max
#include<bits/stdc++.h> using namespace std; const int INF=1e9+10; const int N=1e5; int t,n; long long a[N]; int main(){ scanf("%d",&t); while(t--){ long long ans=0; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lld",&a[i]); } sort(a,a+n); for(int i=0;i<n-1;i++){ ans+=(long long )a[i]; } printf("%lld\n",ans); } return 0; }
二分+前缀和
#include<bits/stdc++.h> using namespace std; const int N=1e5+100; int t,n,m; char str[N]; int p[N]; int solve(int x){ for(int i=0;i+x<=n;i++){ if(p[i+x]-p[i]+m>=x||(i+x-p[i+x])-(i-p[i])+m>=x) return 1; } return 0; } int main(){ scanf("%d",&t); while(t--){ scanf("%d%d%s",&n,&m,str); memset(p,0,sizeof(p)); for(int i=1;i<=n;i++){ if(str[i-1]==‘1‘){ p[i]=p[i-1]+1; } else{ p[i]=p[i-1]; } } int l=0,r=n,mid; while(l<=r){ mid=(l+r)/2; if(solve(mid)) l=mid+1; else r=mid-1; } printf("%d\n",r); } return 0; }
标签:memset sizeof show gre ref turn hide cdc color
原文地址:https://www.cnblogs.com/YJing814/p/10810392.html