ZOJ Problem Set - 3944(interesting people counting))
来源:互联网 发布:mysql开启binlog日志 编辑:程序博客网 时间:2024/06/01 10:04
【链接】:click here~~
【题意】:
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:
.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
【题意】people counting,统计照片中的人数个数。
【思路】统计将可能构成人体的每一部分的周围的其他器官,赋值为一个点,然后暴力即可,注意代码不要出错,之前手残将s[i][j]=’.’写成s[i][j]=’\’WA无数遍!!!
【代码】:
/*ZOJ Problem Set - 3944*/#include <iostream>#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn =1e2+10;inline LL read(){ int c=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();} return c*f;}char s[maxn][maxn];int n,m;int check(int x,int y){ if(x>=0&&x<n && y>=0&&y<m) return true; return false;}int ok1(int sx,int sy) ///'O' 头下面五个可能的部位{ if(s[sx+1][sy-1]=='/' &&check(sx+1,sy-1)) s[sx+1][sy-1]='.'; if(s[sx+1][sy]=='|' &&check(sx+1,sy)) s[sx+1][sy]='.'; if(s[sx+1][sy+1]=='\\' &&check(sx+1,sy+1)) s[sx+1][sy+1]='.'; if(s[sx+2][sy-1]=='(' &&check(sx+2,sy-1)) s[sx+2][sy-1]='.'; if(s[sx+2][sy+1]==')' &&check(sx+2,sy+1)) s[sx+2][sy+1]='.';}int ok2(int sx,int sy)/// '|'{ if(s[sx][sy-1]=='/' &&check(sx,sy-1)) s[sx][sy-1]='.'; if(s[sx][sy+1]=='\\' &&check(sx,sy+1)) s[sx][sy+1]='.'; if(s[sx+1][sy-1]=='(' &&check(sx+1,sy-1)) s[sx+1][sy-1]='.'; if(s[sx+1][sy+1]==')' &&check(sx+1,sy+1)) s[sx+1][sy+1]='.';}int ok3(int sx,int sy)/// '/'{ if(s[sx][sy+1]=='|'&& check(sx,sy+1)) s[sx][sy+1]='.'; if(s[sx][sy+2]=='\\' &&check(sx,sy+2)) s[sx][sy+2]='.'; if(s[sx+1][sy]=='(' &&check(sx+1,sy)) s[sx+1][sy]='.'; if(s[sx+1][sy+2]==')' &&check(sx+1,sy+2)) s[sx+1][sy+2]='.';}int ok4(int sx,int sy) ///'\\'{ if(s[sx+1][sy-2]=='(' &&check(sx+1,sy-2)) s[sx+1][sy-2]='.'; if(s[sx+1][sy]==')' &&check(sx+1,sy)) s[sx+1][sy]='.';}int ok5(int sx,int sy)///'('{ if(s[sx][sy+2]==')' &&check(sx,sy+2)) s[sx][sy+2]='.';}int main(){ //freopen("1.txt","r",stdin); int t;t=read(); while(t--) { n=read();m=read(); for(int i=0; i<n; ++i) { for(int j=0; j<m; ++j) { cin>>s[i][j]; } } int sx,sy,dx,dy; int cnt=0; for(int i=0; i<n; ++i) { for(int j=0; j<m; ++j) { if(s[i][j]=='O') { cnt++; ok1(i,j); } else if(s[i][j]=='|') { cnt++; ok2(i,j); } else if(s[i][j]=='/') { cnt++; ok3(i,j); } else if(s[i][j]=='\\') { cnt++; ok4(i,j); } else if(s[i][j]=='(') { cnt++; ok5(i,j); } else if(s[i][j]==')')cnt++; } } printf("%d\n",cnt); } return 0;}
- ZOJ Problem Set - 3944(interesting people counting))
- ZOJ 3944 People Counting(模拟+暴力)
- ZOJ 3944People Counting
- zoj 3944 People Counting
- zoj-3944-People Counting
- ZOJ-3944 People Counting
- ZOJ 3944People Counting(思维/技巧/模拟)
- zoj 3944 暴力 People Counting
- ZOJ 3944-People Counting【模拟】(2016浙江省大学生程序设计竞赛)
- ZOJ Problem Set - 3405 Counting Factor Trees
- ZOJ Problem Set - 2319 Beautiful People || sgu 199
- zoj 2682 People like People(Kosaraju)
- ZOJ-3944 People Counting From 第13届浙江省赛
- ZOJ Problem Set - 3469(区间dp)
- ZOJ Problem Set - 1078(Palindrom Numbers)
- ZOJ 2724--Problem Set(优先队列)
- ZOJ Problem Set - 1200 (Mining)
- ZOJ Problem Set - 1009 Enigma(待想通)
- 400行代码实现行为树(基于cocos2dx框架下)
- iOS设置Label上显示不同字体大小
- 关于webview的常识
- 交流经过整流桥后的电压计算方法(不权威)
- HTML+CSS基础课程/1-4单学习记录
- ZOJ Problem Set - 3944(interesting people counting))
- nodejs教程 安装express及配置app.js文件的详细步骤
- ClassNotFoundException与NoClassDefFoundError 区别
- runtime 运行时机制 完全解读
- simpleXML操作xml中的特殊情况
- Andrid Studio常用开发插件
- CORS Filter
- 一段具有纪念意义的sql
- java插入mysql乱码(变成问号)