已经写了100篇题解啦!
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; inline int read(){ int f=1,ans=0;char c; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){ans=ans*10+c-‘0‘;c=getchar();} return ans*f; } int x,y,z,a,b,c,ans; int main(){ x=read(),y=read(),z=read(),a=read(),b=read(),c=read(); ans=a+b+c; if(a<x){printf("NO");return 0;} ans-=x; a-=x; if(a+b<y){printf("NO");return 0;} ans-=y; if(ans<z){printf("NO");return 0;} else{printf("YES");return 0;} }
A
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define int long long using namespace std; inline int read(){ int f=1,ans=0;char c; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){ans=ans*10+c-‘0‘;c=getchar();} return ans*f; } const int N=200001; int n,m,k; struct node{ int val,id; }a[N]; bool cmp(node x1,node x2){return x1.val>x2.val;} int s[N],ans; signed main(){ n=read(),m=read(),k=read(); for(int i=1;i<=n;i++) a[i].val=read(),a[i].id=i; sort(a+1,a+n+1,cmp); for(int i=1;i<=m*k;i++) s[++s[0]]=a[i].id,ans+=a[i].val; printf("%lld\n",ans);sort(s+1,s+s[0]+1); for(int i=1;i<k;i++) printf("%lld ",s[i*m]); }
B
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<climits> #define int long long using namespace std; inline int read(){ int f=1,ans=0;char c; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){ans=ans*10+c-‘0‘;c=getchar();} return ans*f; } const int MAXN=1000001; int n,k,num[MAXN],prime[MAXN],cnt,minn=LLONG_MAX; signed main(){ n=read(),k=read(); for(int i=2;i<=sqrt(k);i++){ if(k%i==0){ prime[++cnt]=i; num[cnt]=1;k/=i; while(k%i==0){k/=i;num[cnt]++;} } }if(k>1){prime[++cnt]=k;num[cnt]=1;} for(int i=1;i<=cnt;i++){ int N=n,sum=0; while(N) sum+=(N/prime[i]),N/=prime[i]; sum/=num[i]; minn=min(minn,sum); }printf("%lld\n",minn); }
C
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; inline int read(){ int f=1,ans=0;char c; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){ans=ans*10+c-‘0‘;c=getchar();} return ans*f; } const int MAXN=5001; int f[MAXN][MAXN],n,col[MAXN]; int main(){ n=read(); for(int i=1;i<=n;i++) col[i]=read(); memset(f,127/3,sizeof(f)); for(int i=1;i<=n;i++) f[i][i]=0; for(int len=2;len<=n;len++){ for(int i=1;i+len-1<=n;i++){ int j=i+len-1; if(col[i]==col[j]) f[i][j]=min(f[i][j],f[i+1][j-1]+1); if(col[i]==col[i+1]) f[i][j]=min(f[i][j],f[i+1][j]); else f[i][j]=min(f[i][j],f[i+1][j]+1); if(col[j]==col[j-1]) f[i][j]=min(f[i][j],f[i][j-1]); else f[i][j]=min(f[i][j],f[i][j-1]+1); } }printf("%d\n",f[1][n]); }
D
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<climits> using namespace std; inline int read(){ int f=1,ans=0;char c; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){ans=ans*10+c-‘0‘;c=getchar();} return ans*f; } int ask1(int x){ printf("? %d\n",x);fflush(stdout); int opt=read(); return opt; } int ask2(int x){ printf("> %d\n",x);fflush(stdout); int num=read(); return num; } int qmax(){ int l=0,r=1000000000,maxn=-INT_MAX; while(l<=r){ int mid=(l+r)>>1; if(ask2(mid))maxn=max(maxn,mid),l=mid+1; else r=mid-1; }return maxn+1; }int n,d,a[301]; int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); }int maxn; signed main(){ n=read(); maxn=qmax(); for(int i=1;i<=30;i++){ int s=(rand()*rand())%n+1; a[++a[0]]=ask1(s); }sort(a+1,a+31); d=maxn-a[1]; for(int i=1;i<=29;i++) d=gcd(d,a[i+1]-a[1]); printf("! %d %d\n",maxn-d*(n-1),d);fflush(stdout); return 0; }
E
原文地址:https://www.cnblogs.com/si-rui-yang/p/10362873.html
时间: 2024-10-05 20:24:31