[NOIP2015] 普及组
模拟
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int main(){ 5 int k,n; 6 scanf("%d",&k); 7 int t=0; 8 int day=1;//day记录每日工资 9 int coin=0; 10 while(t<k){//t记录天数 11 for(int i=1;i<=day;i++){ 12 t++; 13 if(t>k)break;//天数到了就停 14 coin+=day; 15 } 16 day++; 17 } 18 printf("%d",coin);//输出 19 return 0; 20 }
1 /*by SilverN*/ 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 const int mx[9]={0,1,0,-1,0,1,1,-1,-1}; 9 const int my[9]={0,0,1,0,-1,1,-1,1,-1}; 10 const int inf=1e5; 11 int n,m; 12 char mp[120][120]; 13 int cnt[120][120]; 14 int main(){ 15 int i,j; 16 scanf("%d%d",&n,&m); 17 memset(mp,'.',sizeof mp); 18 for(i=1;i<=n;i++) 19 scanf("%s",mp[i]+1); 20 for(i=1;i<=n;i++) 21 for(j=1;j<=m;j++){ 22 if(mp[i][j]=='*'){ 23 cnt[i][j]=inf; 24 continue; 25 } 26 for(int k=1;k<=8;k++){ 27 int nx=i+mx[k]; 28 int ny=j+my[k]; 29 // printf("%c ",mp[nx][ny]); 30 if(mp[nx][ny]=='*') 31 ++cnt[i][j]; 32 } 33 } 34 for(i=1;i<=n;i++){ 35 for(j=1;j<=m;j++){ 36 if(cnt[i][j]==inf) 37 printf("*"); 38 else printf("%d",cnt[i][j]); 39 } 40 printf("\n"); 41 42 } 43 return 0; 44 }
数学归纳 扫描
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cmath> 5 using namespace std; 6 const int mxn=100010; 7 int n,m; 8 int num[mxn]; 9 int c[mxn]; 10 int cnt[2][mxn]; 11 int smm[2][mxn]; 12 int main(){ 13 int i,j; 14 scanf("%d%d",&n,&m); 15 for(i=1;i<=n;++i)scanf("%d",&num[i]); 16 for(i=1;i<=n;++i){ 17 scanf("%d",&c[i]); 18 } 19 for(i=1;i<=n;++i){ 20 smm[i&1][c[i]]=(smm[i&1][c[i]]+num[i])%10007; 21 cnt[i&1][c[i]]++; 22 } 23 int ans=0; 24 for(i=1;i<=n;++i){ 25 ans=(ans+i*((smm[i&1][c[i]]+(cnt[i&1][c[i]]-2)*num[i]%10007)%10007))%10007; 26 27 } 28 cout<<ans<<endl; 29 return 0; 30 }
1 /*by SilverN*/ 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 #include<queue> 8 using namespace std; 9 const int mxn=100010; 10 int read(){ 11 int x=0,f=1;char ch=getchar(); 12 while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();} 13 while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();} 14 return x*f; 15 } 16 priority_queue<int>q; 17 int n; 18 int d[mxn]; 19 int a[mxn]; 20 int ans[mxn]; 21 int main(){ 22 n=read(); 23 int i,j; 24 for(i=1;i<=n;i++) 25 d[i]=read(); 26 for(j=1;j<=n;j++) 27 a[j]=read(); 28 int hd=0; 29 for(int m=1;m<=n;m++){ 30 int pos=0,mx=0; 31 for(i=hd+1;i<=n;i++){ 32 if(2*(d[i]-d[hd])+a[i]>mx){ 33 mx=2*(d[i]-d[hd])+a[i]; 34 pos=i; 35 } 36 } 37 // printf("test:%d\n",mx); 38 int tmp=0; 39 if(!q.empty()){ 40 if(q.top()>mx){ 41 ans[m]=ans[m-1]+q.top(); 42 q.pop(); 43 continue; 44 } 45 } 46 ans[m]=ans[m-1]+mx; 47 for(i=hd+1;i<pos;i++){ 48 q.push(a[i]); 49 } 50 hd=pos; 51 } 52 for(i=1;i<=n;i++)printf("%d\n",ans[i]); 53 return 0; 54 }
本文为博主原创文章,转载请注明出处。