zoj-3944-People Counting
来源:互联网 发布:开山刀淘宝哪里有卖 编辑:程序博客网 时间:2024/05/21 07:08
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
数人的个数
看题目的意思搜一遍枚举就好了
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int maxn = 105;char m[maxn][maxn];bool vis[maxn][maxn];int h, w;void check(int r, int c){ vis[r][c] = true; if (m[r][c] == 'O'){ if (r+1<h && m[r+1][c]=='|') vis[r+1][c] = true; if (r+1<h && c+1<w && m[r+1][c+1]=='\\') vis[r+1][c+1] = true; if (r+1<h && c-1>=0 && m[r+1][c-1]=='/') vis[r+1][c-1] = true; if (r+2<h && c-1>=0 && m[r+2][c-1]=='(') vis[r+2][c-1] = true; if (r+2<h && c+1<w && m[r+2][c+1]==')') vis[r+2][c+1] = true; } else if (m[r][c] == '|'){ if (c+1<w && m[r][c+1]=='\\') vis[r][c+1] = true; if (r+1<h && c-1>=0 && m[r+1][c-1]=='(') vis[r+1][c-1] = true; if (r+1<h && c+1<w && m[r+1][c+1]==')') vis[r+1][c+1] = true; } else if (m[r][c] == '/'){ if (c+1<w && m[r][c+1]=='|') vis[r][c+1] = true; if (c+2<w && m[r][c+2]=='\\') vis[r][c+2] = true; if (r+1<h && c+2<w && m[r+1][c+2]==')') vis[r+1][c+2] = true; if (r+1<h && m[r+1][c]=='(') vis[r+1][c] = true; } else if (m[r][c] == '\\'){ if (r+1<h && m[r+1][c]==')') vis[r+1][c] = true; if (r+1<h && c-2>=0 && m[r+1][c-2]=='(') vis[r+1][c-2] = true; } else if (m[r][c] == '('){ if (c+2<w && m[r][c+2]==')') vis[r][c+2] = true; }}int main(){ int t; scanf("%d", &t); while (t--){ scanf("%d%d", &h, &w); for (int i=0; i<h; ++i) scanf("%s", m+i); int cnt = 0; memset(vis, false, sizeof(vis)); for (int i=0; i<h; ++i) for (int j=0; j<w; ++j) if (!vis[i][j] && (m[i][j]=='O'||m[i][j]=='|'||m[i][j]=='/'||m[i][j]=='\\'||m[i][j]=='('||m[i][j]==')')) { ++cnt; check(i, j); } printf("%d\n", cnt); } return 0;}
- ZOJ 3944People Counting
- zoj 3944 People Counting
- zoj-3944-People Counting
- ZOJ-3944 People Counting
- zoj 3944 暴力 People Counting
- ZOJ 3944 People Counting(模拟+暴力)
- ZOJ-3944 People Counting From 第13届浙江省赛
- ZOJ Problem Set - 3944(interesting people counting))
- ZOJ 3944People Counting(思维/技巧/模拟)
- People Counting - 16年浙江省省赛I题 ZOJ 3944
- ZOJ 3944-People Counting【模拟】(2016浙江省大学生程序设计竞赛)
- People Counting
- I People Counting
- ZOJ3944-People Counting
- zoj 2682 People like People
- Zoj-5704题 People Counting (带注释) The 13th ZhejiangProvincial Collegiate Programming Contest – I
- ACM刷题之ZOJ———— People Counting
- zoj 3519 Beautiful People
- mysql左连接、右连接、内连接(等值连接)、全连接
- Java 匿名内部类
- 商业研究(13):下厨房,从投资角度看这个项目的前景和价值
- 如何安装ArcGis和Axwoman
- SlidingMenu初识
- zoj-3944-People Counting
- maven打包时跳过测试
- word2013设置无格式粘贴快捷方式
- noip2014解方程(真不知道那些大神怎么想到取模的,竟然考这个?!)
- spring源码剖析(二)Spring默认标签解析及注册实现
- tcp协议单用户图片上传
- 码农小汪-Map遍历的时候删除元素
- Matlab一个计算不同拉普拉斯矩阵的小函数
- HTML中的列表和表格