您的位置:首页 > 运维架构

【ZOJ3944 The 13th Zhejiang Provincial Collegiate Programming ContestI】【简单模拟】People Counting 照片人数统计 人

2016-04-26 18:47 519 查看
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


Author: Lu, Yi
Source: The 13th Zhejiang Provincial Collegiate Programming Contest

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 105, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int casenum, casei;
char A[3][4] = { ".O.","/|\\","(.)" };
char a

;
bool check(int y, int x)
{
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
if (A[i][j]!='.' && a[y + i][x + j] == A[i][j])return 1;
}
return 0;
}
int main()
{
scanf("%d", &casenum);
for (casei = 1; casei <= casenum; ++casei)
{
int n, m;
scanf("%d%d", &n, &m);
++n; ++m;
MS(a, 0);
for (int i = 2; i <= n; ++i)scanf("%s", a[i] + 2);
int ans = 0;
for (int i = 0; i <= n; ++i)
{
for (int j = 0; j <= m; ++j)ans += check(i, j);
}
printf("%d\n", ans);
}
return 0;
}
/*
【trick&&吐槽】
1,诗诗写这题的时候采取了错误的拓扑思想。
把问题想复杂后>_< 白白浪费了机器时间与罚时,差点血崩
可见做题前,严谨思维的重要性。
2,程序规格化和过程化很重要,可以减少出错。

【题意】
.O. /|\ (.)中非'.'的格子是人的一部分。
给你一个图,图上所有人都是上图姿势,然而存在相互遮挡。
没人被完全遮挡,(不会有人在相同的位置)
问你图上最多一共可以看到多少个人。

【类型】
简单模拟

【分析】
注意:没人在相同的位置!
于是,我可以直接暴力维护每个位置每个人。

【时间复杂度&&优化】
O(nm)

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  题库-ZOJ 水题