看样子2015的普及并不是很难
本人第四题做出来了,第三题居然不会做。。、、我果然弱(。??)ノ
后来看了一下题解恍然大悟、、
金币——简单模拟
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; inline int read(){ int t=1,num=0;char c=getchar(); while(c>‘9‘||c<‘0‘){if(c==‘-‘)t=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){num=num*10+c-‘0‘;c=getchar();} return num*t; } int main() { int n=1,k=read(),t=1,ans=0; while(n<=k){ ans+=t*t; t++;n+=t; } n=(t-n+k);ans+=t*n; printf("%d\n",ans); return 0; }
扫雷游戏——简单模拟
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; inline int read(){ int t=1,num=0;char c=getchar(); while(c>‘9‘||c<‘0‘){if(c==‘-‘)t=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){num=num*10+c-‘0‘;c=getchar();} return num*t; } int n,m,a[111][111]; const int x[8]={-1,-1,-1,0,0,1,1,1}; const int y[8]={-1,0,1,-1,1,-1,0,1}; int main() { n=read();m=read(); for(int i=1;i<=n;i++){ char c[101];scanf("%s",c); for(int j=1;j<=m;j++){ if(c[j-1]==‘*‘)a[i][j]=-1; else a[i][j]=0; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(a[i][j]==-1){printf("*");continue;} for(int k=0;k<8;k++){ int u=i+x[k],v=j+y[k]; if(u<1||v<1||u>n||v>m)continue; if(a[u][v]==-1)a[i][j]++; } printf("%d",a[i][j]); } puts(""); } return 0; }
求和——前缀和
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; inline int read(){ int t=1,num=0;char c=getchar(); while(c>‘9‘||c<‘0‘){if(c==‘-‘)t=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){num=num*10+c-‘0‘;c=getchar();} return num*t; } const int maxn=100010,mod=10007; int n,m,a[maxn],c[maxn];long long ans=0; long long s[maxn][2],s1[maxn][2],s2[maxn][2],s3[maxn][2]; int main() { n=read();m=read(); for(int i=1;i<=n;i++)a[i]=read()%mod; for(int i=1;i<=n;i++)c[i]=read()%mod; for(int i=1;i<=n;i++){ int j=c[i],t=i&1; ans=(ans+s[j][t]*a[i]+((s1[j][t]*i)%mod)*a[i]+s2[j][t]+i*s3[j][t])%mod; s[j][t]=(s[j][t]+i)%mod; s1[j][t]=(s1[j][t]+1)%mod; s2[j][t]=(s2[j][t]+i*a[i])%mod; s3[j][t]=(s3[j][t]+a[i])%mod; } printf("%d\n",ans); return 0; }
推销员——优先队列
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<queue> using namespace std; inline int read(){ int t=1,num=0;char c=getchar(); while(c>‘9‘||c<‘0‘){if(c==‘-‘)t=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){num=num*10+c-‘0‘;c=getchar();} return num*t; } struct hehe{int a,b;}h[100010]; int n,now,ans=0,tmp=1,used[100010]; bool cmp(hehe a,hehe b){return a.a<b.a;} typedef pair<int,int> P; priority_queue<int> q1; struct luo{ int id,a,c; friend bool operator <(const luo x,const luo y){ return x.c<y.c; } }; priority_queue<luo> q2; int main() { n=read(); memset(used,0,sizeof(0)); for(int i=1;i<=n;i++)h[i].a=read(); for(int i=1;i<=n;i++)h[i].b=read(); sort(h+1,h+1+n,cmp); int la; for(int i=1;i<=n;i++) if(h[i].a*2+h[i].b>ans){ ans=h[i].a*2+h[i].b;now=h[i].a;la=i; } used[la]=1; for(int i=1;i<=n;i++){ if(h[i].a<=now)continue; q2.push((luo){i,h[i].a,h[i].a*2+h[i].b}); } printf("%d\n",ans); for(int i=2;i<=n;i++){ while(h[tmp].a<=now&&tmp<=n){ if(!used[tmp])q1.push(h[tmp].b); tmp++; } while(!q2.empty()||(q1.empty()&&q2.top().a<=now))q2.pop(); if(!q2.empty()&&q2.top().c-2*now>q1.top()){ ans+=q2.top().c-2*now; now=q2.top().a; used[q2.top().id]=1; q2.pop(); } else{ans+=q1.top();q1.pop();} printf("%d\n",ans); } return 0; }
本文由Yzyet编写,网址为www.cnblogs.com/Yzyet。非Yzyet同意,禁止转载,侵权者必究。
时间: 2024-11-02 12:53:55