金币

模拟

 #include<iostream>
#include<cstdio>
using namespace std;
int main(){
int k,n;
scanf("%d",&k);
int t=;
int day=;//day记录每日工资
int coin=;
while(t<k){//t记录天数
for(int i=;i<=day;i++){
t++;
if(t>k)break;//天数到了就停
coin+=day;
}
day++;
}
printf("%d",coin);//输出
return ;
}

金币

扫雷游戏

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mx[]={,,,-,,,,-,-};
const int my[]={,,,,-,,-,,-};
const int inf=1e5;
int n,m;
char mp[][];
int cnt[][];
int main(){
int i,j;
scanf("%d%d",&n,&m);
memset(mp,'.',sizeof mp);
for(i=;i<=n;i++)
scanf("%s",mp[i]+);
for(i=;i<=n;i++)
for(j=;j<=m;j++){
if(mp[i][j]=='*'){
cnt[i][j]=inf;
continue;
}
for(int k=;k<=;k++){
int nx=i+mx[k];
int ny=j+my[k];
// printf("%c ",mp[nx][ny]);
if(mp[nx][ny]=='*')
++cnt[i][j];
}
}
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(cnt[i][j]==inf)
printf("*");
else printf("%d",cnt[i][j]);
}
printf("\n"); }
return ;
}

扫雷游戏

求和

数学归纳 扫描

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int mxn=;
int n,m;
int num[mxn];
int c[mxn];
int cnt[][mxn];
int smm[][mxn];
int main(){
int i,j;
scanf("%d%d",&n,&m);
for(i=;i<=n;++i)scanf("%d",&num[i]);
for(i=;i<=n;++i){
scanf("%d",&c[i]);
}
for(i=;i<=n;++i){
smm[i&][c[i]]=(smm[i&][c[i]]+num[i])%;
cnt[i&][c[i]]++;
}
int ans=;
for(i=;i<=n;++i){
ans=(ans+i*((smm[i&][c[i]]+(cnt[i&][c[i]]-)*num[i]%)%))%; }
cout<<ans<<endl;
return ;
}

求和

推销员

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
priority_queue<int>q;
int n;
int d[mxn];
int a[mxn];
int ans[mxn];
int main(){
n=read();
int i,j;
for(i=;i<=n;i++)
d[i]=read();
for(j=;j<=n;j++)
a[j]=read();
int hd=;
for(int m=;m<=n;m++){
int pos=,mx=;
for(i=hd+;i<=n;i++){
if(*(d[i]-d[hd])+a[i]>mx){
mx=*(d[i]-d[hd])+a[i];
pos=i;
}
}
// printf("test:%d\n",mx);
int tmp=;
if(!q.empty()){
if(q.top()>mx){
ans[m]=ans[m-]+q.top();
q.pop();
continue;
}
}
ans[m]=ans[m-]+mx;
for(i=hd+;i<pos;i++){
q.push(a[i]);
}
hd=pos;
}
for(i=;i<=n;i++)printf("%d\n",ans[i]);
return ;
}

推销员

04-15 12:40