hdu 4527

小明系列故事——玩转十滴水

题目大意:游戏是在一个6*6的方格内进行的,每个格子上有一滴水或者没有水滴。水滴分为四个等级1~4。初始时你有十滴水,通过把水加入格子内的水滴,会让水滴升1级。你也可以把水放到空格子内,这样会在这个格子里面产生一个1级的水滴。当水滴等级大于4时则会爆裂为四个小水滴,并向四个方向飞溅。每个飞溅的小水滴碰到其他水滴后会融入其中,使其升一级或者爆裂,以此类推。飞溅的小水滴互不干扰,运动速度相等(1秒可以移动一个格子的距离)。水滴爆裂后就消失掉了。

4527-1

输入:
题目包含多组测试用例;
对于每组数据,首先是6行,每行有6个整数数字,每个数字的范围为0~4;当数字为0时,表示空格子,当数字为1~4时,表示1~4级的水滴;
然后第七行是一个整数m,表示有m个操作;接下来是m行,每行有两个整数x, y ,表示在(x,y)放入一滴水。
特别说明:每次都是在全部的水滴静止后才进行下一次操作,也就是说只有在方格内没有任何飞溅的小水滴时才能放入一滴水。

[Technical Specification]

1 <= m <= 10

1 <= x, y <= 6

输出:
对于每组测试数据,请输出m个操作之后6*6方格内水滴的样子,每组数据的输出后面跟着一个空行。

思考:水滴的爆裂 和 水滴的飞溅一定同时进行,以保证每一个运动时刻游戏状态都是正确的!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// main.cpp
// hdu 4527
//
// Created by miaoyou.gmy on 15/8/30.
// Copyright (c) 2015年 miaoyou.gmy. All rights reserved.
//

#include <iostream>
#include <string.h>
#include <queue>
using namespace std;

struct node{
int x,y,d;
node(int _x = 0,int _y = 0,int _d = 0):x(_x),y(_y),d(_d){}
};

const int N(6);
int maze[N][N];
queue<node> Q;
const int dir[4][2] = { {0,1},{1,0},{-1,0},{0,-1} };

bool judge(const int x,const int y){
return (x>-1&&x<N&&y>-1&&y<N);
}

void output(){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(j == 0) printf("%d",maze[i][j]);
else printf(" %d",maze[i][j]);
}
printf("\n");
}
printf("\n");
}

void deal(const int x,const int y){
maze[x][y] = 0;
for(int i=0;i<4;i++){
int xx = x+dir[i][0];
int yy = y+dir[i][1];
if(judge(xx, yy)){
Q.push(node(xx,yy,i));
}
}
}

void found(){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(maze[i][j] > 4) deal(i, j);
}
}
}

void bfs(){
while (!Q.empty()) {
size_t size = Q.size();
while(size--){
node now = Q.front();
Q.pop();

if(maze[now.x][now.y] > 0) maze[now.x][now.y]+=1;
else{
int afterx = now.x+dir[now.d][0];
int aftery = now.y+dir[now.d][1];
if(judge(afterx, aftery)){
Q.push(node(afterx,aftery,now.d));
}
}
}
found();
}
}


int main(int argc, const char * argv[]) {
// freopen("in.txt", "r", stdin);
int a,m,x,y;
while(~scanf("%d",&a)){
maze[0][0] = a;
for(int i=1;i<N;i++){
scanf("%d",&maze[0][i]);
}

for(int i=1;i<N;i++){
for(int j=0;j<N;j++){
scanf("%d",&maze[i][j]);
}
}

scanf("%d",&m);
while(m--){
scanf("%d%d",&x,&y);
--x,--y;
if(maze[x][y] < 4) maze[x][y]+=1;
else{
deal(x,y);
bfs();
}
}
output();
}
return 0;
}

hdu-4527-accepted

如有任何知识产权、版权问题或理论错误,还请指正。

转载请注明原作者及以上信息。

hdu 3839

Ancient Messages

题目大意:给出以下6种象形文字,编程识别出来。
figureC1

输入:有多组测试样例,每组测试样例使用0(白色像素) 和 1(黑色像素)来描述一张图片。出于节约空间的目的,使用1位16进制数 表示 4位二进制数。图片最大size为(50 200)。二进制解码之后实际大小为(200 200)

给出的测试样例符合以下条件:

  • 图片中只会出现 这6种象形文字
  • 图片中至少有一个象形文字存在
  • 每一个黑色像素都是一个象形文字的一部分(可以理解为文字笔画是标准的)
  • 黑色像素是拼接成了文字笔画
  • 文字之间不会有重叠 和 接触
  • 两颗黑色像素如果是对角接触,也可以认为这两个像素是同一个文字的一部分。(这个条件我貌似没在意,遍历只在乎 上左下右 四个方向)
  • 文字可能会比较潦草,但还是6个象形文字的符号结构

输出: 字母顺序 输出图片中的所有象形文字

思考:题目乍一看毫无头绪,但是观察这6种符号,就能发现一个明显的特征,每一种符号都有各自的“封闭区域”。

AnKh有1个“封闭区域”,Wedjat有3个“封闭区域”,Djed有5个“封闭区域”,Scarab有4个“封闭区域”,Was有0个“封闭区域”,Akeht有2个“封闭区域”。

我们可以对不同的“封闭区域”进行染色标记,再沿着黑色像素遍历,看能接触到多少种不同颜色的“封闭区域”。 如果有1种的话,那么所遍历的黑色像素 描绘的就是 Was符号了,以此类推

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// main.cpp
// hdu 3839
//
// Created by miaoyou.gmy on 15/8/29.
// Copyright (c) 2015年 miaoyou.gmy. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
const int H = 205;
const int W = 205;
int maze[H][W],h,w,colorCount;
bool colorVis[H],vis[H][W];
const int dir[4][2] = { {0,1},{1,0},{-1,0},{0,-1} };
const char hieroglyphMap[] = {'W','A','K','J','S','D'};

bool judge(const int x, const int y){
return (x>-1&&x<h&&y>-1&&y<w&&!vis[x][y]);
}

void dfs(int x,int y,int color){
maze[x][y] = color;
for(int i = 0; i < 4; i++){
int xx = x+dir[i][0];
int yy = y+dir[i][1];
if(judge(xx,yy) && !maze[xx][yy]){
vis[xx][yy] = true;
dfs(xx,yy,color);
}
}
}

void countDiffentColor(int x,int y){
for(int i = 0; i < 4; i++){
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if(judge(xx, yy)){
if(maze[xx][yy] != 1){
if(!colorVis[maze[xx][yy]]) colorCount++;
colorVis[maze[xx][yy]] = true;
}
else{
vis[xx][yy] = true;
countDiffentColor(xx, yy);
}
}
}
}



int main(int argc, const char * argv[]) {
int caseNumber = 1;
while(~scanf("%d%d",&h,&w)){
if(0 == h && 0 == w) break;
memset(maze, 0, sizeof(int) * H * W);
char strs[51];
for(int i = 0; i < h; i++){
scanf("%s",strs);
for(int j = 0; j < w; j++){
int tmp = 0;
if(strs[j]>='0' && strs[j]<='9') tmp = strs[j] - '0';
else tmp = 10+strs[j]-'a';

for(int k = 0; k < 4 ; k++){
maze[i+1][4*j+k+1] = ((tmp>>(3-k))&1);
}
}
}

h+=2, w*=4,w+=2;
int color = 2;
memset(vis, false, sizeof(bool) * H * W);
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(!maze[i][j]){
dfs(i,j,color);
color++;
}
}
}
vector<char> ans;
memset(vis, false, sizeof(bool) * H * W);
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(maze[i][j] == 1 && !vis[i][j]){
colorCount = 0;
memset(colorVis, false, sizeof(bool) * H);
countDiffentColor(i,j);
ans.push_back(hieroglyphMap[colorCount - 1]);
}
}
}
sort(ans.begin(), ans.end());
string str(ans.begin(),ans.end());
cout<<"Case "<<caseNumber++<<": "<<str<<endl;
}
return 0;
}

hdu-3839-accepted

如有任何知识产权、版权问题或理论错误,还请指正。

转载请注明原作者及以上信息。