ZOJ 3944 People Counting(模拟+暴力)
来源:互联网 发布:特朗普政治主张知乎 编辑:程序博客网 时间:2024/05/22 00:24
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
题目大意:寻找有多少个小人(只出现一部分也属于一个小人)
#include <cmath>#include <queue>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#define LL long long#define INF 0x3f3f3f3f#define RR freopen("D:\\in.txt","r",stdin)#define WW freopen("D:\\out.txt","w",stdout)using namespace std;int n,m;char Map[110][110];char Peo[5][5] = {".O.", "/|\\", "(.)" };bool Judge_in(int x, int y){ if(x >= 1 && x <= n && y >=1 && y <= m) return true; return false;}bool Judge_c(char x, char y){ if(x == '#' || y == '.' || x == y) return false; return true;}bool Judge(int x, int y){ for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { if(Judge_in(x+i, y+j) && Judge_c(Map[i+x][j+y], Peo[i][j])) { return false; } } } return true;}void Find(int &x, int &y, char ch){ for(int i=0; i<3; i++) for(int j=0; j<3; j++) if(ch == Peo[i][j]) x = i, y = j;}int Num(){ int ret = 0; for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { if(Map[i][j] != '#' && Map[i][j] != '.') { int x, y; Find(x, y, Map[i][j]); x = i - x, y = j - y; if(Judge(x, y)) { ret++; for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { int xx = x + i; int yy = y + j; if(Judge_in(xx, yy) && Peo[i][j] != '.') { Map[xx][yy] = '#'; } } } } } } } return ret;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) { scanf("%s", Map[i]+1); } int ans = 0, tmp; while(tmp = Num()) ans += tmp; printf("%d\n",ans); } return 0;}
- ZOJ 3944 People Counting(模拟+暴力)
- zoj 3944 暴力 People Counting
- ZOJ 3944People Counting(思维/技巧/模拟)
- ZOJ 3944People Counting
- zoj 3944 People Counting
- zoj-3944-People Counting
- ZOJ-3944 People Counting
- ZOJ 3944-People Counting【模拟】(2016浙江省大学生程序设计竞赛)
- ZOJ Problem Set - 3944(interesting people counting))
- ZOJ-3944 People Counting From 第13届浙江省赛
- People Counting - 16年浙江省省赛I题 ZOJ 3944
- zoj 2682 People like People(Kosaraju)
- People Counting
- zoj--3935--2016(暴力模拟)(数学)
- I People Counting
- ZOJ3944-People Counting
- zoj 2682 People like People
- ZOJ 3465 The Hive 暴力模拟
- jquery的deferred使用详解
- mysql tee config
- linux查看java jdk安装路径和设置环境变量
- 三帧差分算法
- easyui表格复选框的全选键是否选中
- ZOJ 3944 People Counting(模拟+暴力)
- android面试题(一)
- 删除vector中重复元素
- Maven私服nexus
- 一个列表展示的瀑布流
- android 的内存、内部存储和外部存储的理解/cache/system。
- 熟悉linux的基本操作
- 使用faster rcnn训练imageNet上的部分数据集(1)
- openssl 链接服务器