ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题。
ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3944
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 /////////////////////////////////////////////////////////////////////////
刚读完题的我是无比懵逼的。。。
冷静下来,发现有几点对解题还是有用的。
1 每个人都至少有一部分漏出来。
2 大家的站姿相同,也就是说,每个人躯体的各个部分的相对位置是确定的。如果你找到了一只手,那么在确定的地方可能会出现这个人的另一只手。。。 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <stdlib.h>
# define MAXN 110
typedef long long int LL;
using namespace std; char in[MAXN][MAXN];
int t, p, w;
int head[5][2] = {{1,-1}, {1,0}, {1,1}, {2,-1}, {2,1}};
char headwing[6] = {"/|\\()"};
int leftarm[5][2] = {{-1,1}, {0,1}, {0,2}, {1,0}, {1,2}};
char leftarmwing[6] = {"O|\\()"};
int mid[5][2] = {{-1,0}, {0,-1}, {0,1}, {1,-1}, {1,1}};
char midwing[6] = {"O/\\()"};
int rightarm[5][2] = {{-1,-1}, {0,-2}, {0,-1}, {1,-2}, {1,0}};
char rightarmwing[6] = {"O/|()"};
int leftleg[5][2] = {{-2,1}, {-1,0}, {-1,1}, {-1,2}, {0,2}};
char leftlegwing[6] = {"O/|\\)"};
int rightleg[5][2] = {{-2,-1}, {-1,-2}, {-1,-1}, {-1,0}, {0,-2}};
char rightlegwing[6] = {"O/|\\("}; void check(int i, int j){
int k = 0, x, y;
if(in[i][j] == 'O'){
for(k=0; k<5; ++k){
x = i + head[k][0];
y = j + head[k][1];
if(x < 0 || x>=p || y<0 || y>=w){
continue;
}else{
if(in[x][y] == headwing[k]){
in[x][y] = '.';
}
}
}
}else if(in[i][j] == '/'){
for(k=0; k<5; ++k){
x = i + leftarm[k][0];
y = j + leftarm[k][1];
if(x < 0 || x>=p || y<0 || y>=w){
continue;
}else{
if(in[x][y] == leftarmwing[k]){
in[x][y] = '.';
}
}
}
}else if(in[i][j] == '|'){
for(k=0; k<5; ++k){
x = i + mid[k][0];
y = j + mid[k][1];
if(x < 0 || x>=p || y<0 || y>=w){
continue;
}else{
if(in[x][y] == midwing[k]){
in[x][y] = '.';
}
}
}
}else if(in[i][j] == '\\'){
for(k=0; k<5; ++k){
x = i + rightarm[k][0];
y = j + rightarm[k][1];
if(x < 0 || x>=p || y<0 || y>=w){
continue;
}else{
if(in[x][y] == rightarmwing[k]){
in[x][y] = '.';
}
}
}
}else if(in[i][j] == '('){
for(k=0; k<5; ++k){
x = i + leftleg[k][0];
y = j + leftleg[k][1];
if(x < 0 || x>=p || y<0 || y>=w){
continue;
}else{
if(in[x][y] == leftlegwing[k]){
in[x][y] = '.';
}
}
}
}else if(in[i][j] == ')'){
for(k=0; k<5; ++k){
x = i + rightleg[k][0];
y = j + rightleg[k][1];
if(x < 0 || x>=p || y<0 || y>=w){
continue;
}else{
if(in[x][y] == rightlegwing[k]){
in[x][y] = '.';
}
}
}
}
return ;
}
int main(){
//freopen("in.txt", "r", stdin);
scanf("%d", &t);
while( t-- ){
scanf("%d%d", &p, &w);
getchar();
memset(in, 0, sizeof(in));
for(int i=0; i<p; ++i){
for(int j=0; j<w; ++j){
scanf("%c", &in[i][j]);
}
getchar();
}
int ans = 0;
for(int i=0; i<p; ++i){
for(int j=0; j<w; ++j){
if(in[i][j] == '.'){
continue;
}else{
ans ++;
check(i,j);
in[i][j] = '.';
}
}
}
cout << ans << endl;
} return 0;
} // 代码写的这么长,真的很抱歉 :(。
ZOJ People Counting的更多相关文章
- [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)
Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...
- ZOJ 2392 The Counting Problem(模拟)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1368 题目大意:计算从S到T中所有的数,其中0,1,2,3,4,5, ...
- zoj 1610 Count the Colors
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610 Count the Colors Time Limit:2000MS ...
- ZOJ 3080 ChiBi(spfa)
ZOJ Problem Set - 3080 ChiBi Time Limit: 5 Seconds Memory Limit: 32768 KB watashi's mm is so pr ...
- zoj 3286 Very Simple Counting---统计[1,N]相同因子个数
Very Simple Counting Time Limit: 1 Second Memory Limit: 32768 KB Let f(n) be the number of fact ...
- ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)
ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting s ...
- TOJ 1258 Very Simple Counting
Description Let f(n) be the number of factors of integer n. Your task is to count the number of i(1 ...
- ZOJ 1610——Count the Colors——————【线段树区间替换、求不同颜色区间段数】
Count the Colors Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- zoj 1610 Count the Colors 【区间覆盖 求染色段】
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
随机推荐
- 安卓与IOS移动段浏览器视频与音频的问题与总结
1. 安卓.苹果移动浏览器上都不支持html5的视频与音频自动播放 2. 安卓.苹果移动浏览器要支持播放,前提是必须是用户触发的事件 3. 针对这个特殊的问题,代码需要在用户进来第一次屏幕触发中,去创 ...
- 关于for循环中,定义的i的作用域的问题。
for(var i=0;i<2;i++){ console.log(i) } console.log(i) 经过测试:在IE9+,谷歌,火狐中.都出现了0,1,2三个值. 所以其作用域在整个上下 ...
- 基於tiny4412的Linux內核移植--- 中斷和GPIO學習(1)
作者 彭東林 pengdonglin137@163.com 平臺 tiny4412 ADK Linux-4.4.4 u-boot使用的U-Boot 2010.12,是友善自帶的,爲支持設備樹和uIma ...
- Vertica 分区表设计
Vertica数据库中的表只是一个逻辑概念. 实际存储在磁盘上的是projection. 当创建一张表,没有创建projection时,那么插入数据的时候会自动创建一个默认的projection.如果 ...
- Vertica节点宕机处理一例
Vertica节点宕机处理一例: 查询数据库版本和各节点状态 常规方式启动宕机节点失败 进一步查看宕机节点的详细日志 定位问题并解决 1. 查询数据库版本和各节点状态 dbadmin=> sel ...
- TeamCity : 配置 Build 过程
Build 过程往往是比较复杂的,因此 TeamCtiy 通过 build 步骤的方式让您可以实现不同的应用场景.您可以在每个 build 步骤中只做一件事情,然后把一系列的 build 步骤组织起来 ...
- 自己封装的一个原生JS拖动方法。
代码: function drag(t,p){ var point = p || null, target = t || null, resultX = 0, resultY = 0; (!point ...
- C#开发微信门户及应用(31)--微信语义理解接口的实现和处理
微信语义理解接口提供从用户自然语言输入到结构化解析的技术实现,使用先进的自然语言处理技术给开发者提供一站式的语义解析方案.该平台覆盖多个垂直领域的语义场景,部分领域还可以支持取得最终的展示结果.开发者 ...
- 一段良好的程序永远不应该发生panic异常
panic来自被调函数的信号,表示发生了某个已知的bug.一段良好的程序永远不应该发生panic异常 对于大部分程序而言,永远无法保证能够成功运行,因为错误原因往往超出程序员的控制范围.任何进行io操 ...
- STL的std::find和std::find_if
std::find是用来查找容器元素算法,但是它只能查找容器元素为基本数据类型,如果想要查找类类型,应该使用find_if. 小例子: #include "stdafx.h" #i ...