题目
测试得分: 100
主要算法 : 模拟
题干:
模拟水题
代码
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<iostream> #define FORa(i,s,e) for(int i=s;i<=e;i++) #define FORs(i,s,e) for(int i=s;i>=e;i--) #define File(name) freopen(name".in","r",stdin);freopen(name".out","w",stdout); using namespace std; const int N=30,M=30; int n,m,k,q,a[N+2][M+2]; bool bz[N+2][M+2]; struct Node{ int x,y; }nodek[(N+1)*(M+1)]; int mx[8]={-1,-1,-1,+0,+0,+1,+1,+1}, my[8]={-1,+0,+1,-1,+1,-1,+0,+1}; void Init() { scanf("%d%d%d%d",&n,&m,&k,&q); int x,y; FORa(i,1,k) { scanf("%d%d",&nodek[i].x,&nodek[i].y); a[nodek[i].x][nodek[i].y]=-1; } FORa(i,1,k) FORa(j,0,7) if(a[nodek[i].x+mx[j]][nodek[i].y+my[j]]!=-1&&nodek[i].x+mx[j]>=1&&nodek[i].x+mx[j]<=n&&nodek[i].y+my[j]>=1&&nodek[i].y+my[j]<=m) a[nodek[i].x+mx[j]][nodek[i].y+my[j]]++; } int Solve() { const string s1="Click",s2="Right-Click",s3="Double-Click"; string s; int x,y; FORa(i,1,q) { cin>>s; if(s==s1) { scanf("%d%d",&x,&y); if(bz[x][y]) printf("Illegal Operation!\n"); else if(a[x][y]==-1) printf("It is a mine, try again.\n"); else { if(a[x][y]) printf("%d\n",a[x][y]); else printf("Nothing\n"); bz[x][y]=1; } } else if(s==s2) { scanf("%d%d",&x,&y); if(!bz[x][y]) { if(a[x][y]==-1) printf("Good!\n"),bz[x][y]=1; else printf("It is not a mine, try again.\n"); } else bz[x][y]=0; } else if(s==s3) { scanf("%d%d",&x,&y); if(bz[x][y]&&a[x][y]!=-1&&a[x][y]!=0) { int cnt=0; FORa(j,0,7) if(a[x+mx[j]][y+my[j]]==-1&&bz[x+mx[j]][y+my[j]]) cnt++; if(cnt==a[x][y]) { FORa(j,0,7) bz[x+mx[j]][y+my[j]]=1; } else printf("Illegal Operation!\n"); } else printf("Illegal Operation!\n"); } else { FORa(ii,1,n) { FORa(jj,1,m) { if(bz[ii][jj]&&a[ii][jj]!=-1&&a[ii][jj]!=0) printf("%d",a[ii][jj]); else if(bz[ii][jj]&&a[ii][jj]==-1) printf("@"); else if(bz[ii][jj]&&a[ii][jj]==0) printf("#"); else printf("*"); } printf("\n"); } } } } int main() { File("mine"); Init(),Solve(); return 0; }