扫雷游戏
程序员文章站
2024-03-16 22:29:58
...
http://icpc.upc.edu.cn/problem.php?cid=1585&pid=7
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdlib>
#include<cmath>
using namespace std;
int f,i,j,k,l,b[100000],n,m,ans,a[100000];
int main(){
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d",&a[i]);
b[1]=0;
f=0;
b[2]=a[1]-b[1];
for (i=3;i<=n;i++){
b[i]=a[i-1]-b[i-1]-b[i-2];
if (b[i]>1) {
f=1;
break;
}
}
if (b[n]!=a[n]-b[n-1]) f=1;
if (f){
b[1]=1;
b[2]=a[1]-b[1];
for (i=3;i<=n;i++)
b[i]=a[i-1]-b[i-1]-b[i-2];
}
for (i=1;i<=n;i++){
if (b[i]) ans++;
printf("%d",b[i]);
}
printf("\n");
printf("%d\n",ans);
}