省赛I题,感觉这题做出来就已经可以铜牌了...好怪的题目,感觉省赛都是挺简单,但是挺容易犯错的题
题目要求找出所有的人,
/*
OOO
OOO
OOO
*/
想上面这种所有都是头的竟然就算了9个人,将一个器官的周围可能的情况都尽量归为一个点
遍历每个节点,附件器官清零,遍历模拟的时候还是挺容易犯错的,特别是‘\‘这种,我就忘了把‘(‘讨论了,wa了三次
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib> #include <algorithm> #include <string> #include <stack> #include <queue> const int inf= (1<<31)-1; const int MAXN = 1e2+10; using namespace std; char g[MAXN][MAXN]; int n,m; int check(int x,int y){ if(x<1||y<1||x>n||y>m)return 0; else return 1; } /* OOO OOO OOO */ int main() { int t; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%s",g+i); for(int j=m;j>=1;j--) g[i][j] = g[i][j-1]; } /*for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) printf("%c\n",g[i][j]); cout<<endl; }*/ int sum=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(g[i][j]==‘O‘){ sum+= 1; // cout<<sum<<endl; if(check(i+1,j)&&g[i+1][j]==‘|‘){ g[i+1][j] = ‘.‘; }if(check(i+1,j-1)&&g[i+1][j-1]==‘/‘){ g[i+1][j-1] = ‘.‘; }if(check(i+1,j+1)&&g[i+1][j+1]==‘\\‘){ g[i+1][j+1] = ‘.‘; }if(check(i+2,j-1)&&g[i+2][j-1]==‘(‘){ g[i+2][j-1] = ‘.‘; }if(check(i+2,j+1)&&g[i+2][j+1]==‘)‘){ g[i+2][j+1] = ‘.‘; } }else if(g[i][j]==‘|‘){ sum+=1; if(check(i,j+1)&&g[i][j+1]==‘\\‘){ g[i][j+1] = ‘.‘; }if(check(i+1,j-1)&&g[i+1][j-1]==‘(‘){ g[i+1][j-1] = ‘.‘; }if(check(i+1,j+1)&&g[i+1][j+1]==‘)‘){ g[i+1][j+1] = ‘.‘; } }else if(g[i][j]==‘/‘){ sum+=1; if(check(i,j+1)&&g[i][j+1]==‘|‘){ g[i][j+1] = ‘.‘; }if(check(i,j+2)&&g[i][j+2]==‘\\‘){ g[i][j+2] = ‘.‘; }if(check(i+1,j)&&g[i+1][j]==‘(‘){ g[i+1][j] = ‘.‘; }if(check(i+1,j+2)&&g[i+1][j+2]==‘)‘){ g[i+1][j+2] = ‘.‘; } }else if(g[i][j]==‘\\‘){ sum+=1; if(check(i+1,j)&&g[i+1][j]==‘)‘) g[i+1][j] = ‘.‘; if(check(i+1,j-2)&&g[i+1][j-2]==‘(‘) //error prone g[i+1][j-2] = ‘.‘; }else if(g[i][j]==‘(‘){ sum+=1; if(check(i,j+2)&&g[i][j+2]==‘)‘) g[i][j+2] = ‘.‘; }else if(g[i][j]==‘)‘){ sum+=1; } } } printf("%d\n",sum); } //cout << "Hello world!" << endl; return 0; }
时间: 2024-11-12 03:54:07