浙江16年省赛 I题 People Counting
2016-04-23 19:56
239 查看
People Counting
Time Limit: 2 Seconds Memory Limit: 65536 KB
In a BG (dinner gathering) for ZJU ICPC team, the coaches wanted to count the number of people present at the BG. They did that by having the waitress take a photo for them. Everyone
was in the photo and no one was completely blocked. Each person in the photo has the same posture. After some preprocessing, the photo was converted into a H×W character matrix, with the background represented by ".". Thus a person in this photo
is represented by the diagram in the following three lines:
Given the character matrix, the coaches want you to count the number of people in the photo. Note that if someone is partly blocked in the photo, only part of the above diagram will be
presented in the character matrix.
The first contains two integers H, W (1 ≤ H, W ≤ 100) - as described above, followed by H lines, showing the matrix representation
of the photo.
数小人每次删去一个人即可
ACcode:
Time Limit: 2 Seconds Memory Limit: 65536 KB
In a BG (dinner gathering) for ZJU ICPC team, the coaches wanted to count the number of people present at the BG. They did that by having the waitress take a photo for them. Everyone
was in the photo and no one was completely blocked. Each person in the photo has the same posture. After some preprocessing, the photo was converted into a H×W character matrix, with the background represented by ".". Thus a person in this photo
is represented by the diagram in the following three lines:
.O. /|\ (.)
Given the character matrix, the coaches want you to count the number of people in the photo. Note that if someone is partly blocked in the photo, only part of the above diagram will be
presented in the character matrix.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:The first contains two integers H, W (1 ≤ H, W ≤ 100) - as described above, followed by H lines, showing the matrix representation
of the photo.
Output
For each test case, there should be a single line, containing an integer indicating the number of people from the photo.Sample Input
2
3 3
.O. /|\ (.)3 4
OOO(
/|\\
()))
Sample Output
1 4
数小人每次删去一个人即可
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制 #pragma comment(linker, "/STACK:102400000,102400000")//手工开栈 #include <map> #include <set> #include <queue> #include <cmath> #include <stack> #include <cctype> #include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include <algorithm> #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define rd3(x,y,z) scanf("%d%d%d,&x,&y,&z) #define rdl(x) scanf("%I64d,&x); #define rds(x) scanf("%s",x) #define rdc(x) scanf("%c",&x) #define ll long long int #define ull unsigned long long #define maxn 1005 #define mod 1000000007 #define INF 0x3f3f3f3f //int 最大值 #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i) #define MT(x,i) memset(x,i,sizeof(x)) #define PI acos(-1.0) #define E exp(1) #define eps 1e-8 ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);} ll mul(ll a,ll b,ll p){ll sum=0;for(;b;a=(a+a)%p,b>>=1)if(b&1)sum=(sum+a)%p;return sum;} inline void Scan(int &x) { char c;while((c=getchar())<'0' || c>'9');x=c-'0'; while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0'; } using namespace std; char dp[maxn][maxn]; int x,y,n,m; void gao(){ if(dp[x][y]=='O'){ if(dp[x+1][y]=='|')dp[x+1][y]='.'; if(dp[x+1][y-1]=='/')dp[x+1][y-1]='.'; if(dp[x+1][y+1]=='\\')dp[x+1][y+1]='.'; if(dp[x+2][y-1]=='(')dp[x+2][y-1]='.'; if(dp[x+2][y+1]==')')dp[x+2][y+1]='.'; } else if(dp[x][y]=='|'){ if(dp[x-1][y]=='O')dp[x-1][y]='.'; if(dp[x][y-1]=='/')dp[x][y-1]='.'; if(dp[x][y+1]=='\\')dp[x][y+1]='.'; if(dp[x+1][y-1]=='(')dp[x+1][y-1]='.'; if(dp[x+1][y+1]==')')dp[x+1][y+1]='.'; } else if(dp[x][y]=='/'){ if(dp[x-1][y+1]=='O')dp[x-1][y+1]='.'; if(dp[x][y+1]=='|')dp[x][y+1]='.'; if(dp[x][y+2]=='\\')dp[x][y+2]='.'; if(dp[x+1][y]=='(')dp[x+1][y]='.'; if(dp[x+1][y+2]==')')dp[x+1][y+2]='.'; } else if(dp[x][y]=='\\'){ if(dp[x-1][y-1]=='O')dp[x-1][y-1]='.'; if(dp[x][y-1]=='|')dp[x][y-1]='.'; if(dp[x][y-2]=='/')dp[x][y-2]='.'; if(dp[x+1][y-2]=='(')dp[x+1][y-2]='.'; if(dp[x+1][y]==')')dp[x+1][y]='.'; } else if(dp[x][y]=='('){ if(dp[x-2][y+1]=='O')dp[x-2][y+1]='.'; if(dp[x-1][y]=='/')dp[x-1][y]='.'; if(dp[x-1][y+1]=='|')dp[x-1][y+1]='.'; if(dp[x-1][y+2]=='\\')dp[x-1][y+2]='.'; if(dp[x][y+2]==')')dp[x][y+2]='.'; } else if(dp[x][y]==')'){ if(dp[x-2][y-1]=='O')dp[x-2][y-1]='.'; if(dp[x-1][y-2]=='/')dp[x-1][y-2]='.'; if(dp[x-1][y-1]=='|')dp[x-1][y-1]='.'; if(dp[x-1][y]=='\\')dp[x-1][y]='.'; if(dp[x][y-2]==')')dp[x][y-2]='.'; } dp[x][y]='.'; /* for(int i=1+5;i<=n+5;++i){ for(int j=1+5;j<=m+5;++j)cout<<dp[i][j]; cout<<'\12';}*/ } int juge(){ for(int i=1+5;i<=n+5;++i) for(int j=1+5;j<=m+5;++j) if(dp[i][j]!='.'){ x=i; y=j; gao(); return 1; } return 0; } void init(){ for(int i=0;i<maxn;++i)for(int j=0;j<maxn;++j)dp[i][j]='.'; } int main(){ int loop,cnt=1; rd(loop); while(loop--){ rd2(n,m); // init(); for(int i=1+5;i<=n+5;++i) for(int j=1+5;j<=m+5;++j)cin>>dp[i][j]; int ans=0; while(juge())ans++; printf("%d\n",ans); } return 0; }
相关文章推荐
- Tomcat项目部署方式
- Linux内核模块的概念和基本的编程方法
- MySQL 高可用:mysql-mmm 负载均衡及故障转移
- 如何让Anddroid手机访问电脑的Tomcat服务
- hdu 3242 List Operations
- Linux内核
- db2 - 如何在shell中获取存储过程OUT型参数的返回值(awk)
- 高可用性系统在大众点评的实践与经验
- 简单实例讲解linux的module模块编译步骤
- linux下apache+mod_jk.so+tomcat整合(基础版)
- Linux /dev目录详解和Linux系统各个目录的作用
- 每天一个linux命令(15):tail命令
- shell变量详解
- ZedBoard--(4)嵌入式Linux下的LED实验(PS + PL)
- [树莓派2]--arm-linux交叉编译环境的建立
- shell之作业控制和操作目录栈
- linux分期挂载永久生效
- 基于CentOS7上的搭建javaweb环境 - 学习笔记
- eclipse 配置jdk tomcat配置
- Linux内核分析课程期中总结