HDU - 4527 小明系列故事――玩转十滴水
来源:互联网 发布:java中md5加密怎么写 编辑:程序博客网 时间:2024/04/30 13:30
题意:中文题,看了学长的发现自己没注意到要先同一秒的先走完,BFS
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 10010;const int INF = 0x3f3f3f3f;int m;int map[8][8];int dir[][2] = {{-1,0},{1,0},{0,-1},{0,1}}; struct Node{ int x,y; int cnt; int dir;}Q[500000];void addQue(int x,int y,int cnt,int &rear){ map[x][y] = 0; for (int i = 0; i < 4; i++){ int dx = x + dir[i][0]; int dy = y + dir[i][1]; if (dx >= 1 && dx <= 6 && dy >= 1 && dy <= 6){ Q[rear].x = dx; Q[rear].y = dy; Q[rear].cnt = cnt; Q[rear++].dir = i; } }}void bfs(int x, int y){ int front=0, rear=0; addQue(x, y, 0, rear); int cur = 0; //当前第几秒 while(front < rear){ while(front < rear && Q[front].cnt==cur){ // 把这一秒的全走完 Node &t = Q[front++]; if(map[t.x][t.y]){ ++map[t.x][t.y]; } else{ Node& now = Q[rear]; now.x = t.x + dir[t.dir][0]; now.y = t.y + dir[t.dir][1]; now.cnt = t.cnt + 1; now.dir = t.dir; if(now.x>=1&&now.x<=6&&now.y>=1&&now.y<=6) ++rear; } } for(int i=1; i<=6; ++i){ for(int j=1; j<=6; ++j) if(map[i][j]>4){ addQue(i,j,cur+1,rear); } } ++cur; } }int main(){ int x,y; while (scanf("%d",&map[1][1]) != EOF){ for (int i = 1; i <= 6; i++) for (int j = (i==1?2:1); j <= 6; j++) scanf("%d",&map[i][j]); scanf("%d",&m); for (int i = 0; i < m; i++){ scanf("%d%d",&x,&y); if (++map[x][y] > 4) bfs(x,y); } for (int i = 1; i <= 6; i++){ for (int j = 1; j <= 6; j++) if (j != 1) printf(" %d",map[i][j]); else printf("%d",map[i][j]); printf("\n"); } printf("\n"); } return 0;}
- HDU - 4527 小明系列故事――玩转十滴水
- Hdu 4527 小明系列故事——玩转十滴水
- hdu 4527 小明系列故事——玩转十滴水
- hdu 4527 ——小明系列故事——玩转十滴水
- HDU 4527 小明系列故事——玩转十滴水
- hdu 4527 小明系列故事——玩转十滴水(模拟+BFS)
- hdu 4527 小明系列故事——玩转十滴水 bfs 解题报告
- 小明系列故事——玩转十滴水
- 小明系列故事——玩转十滴水
- HDU 4527 小明系列故事——玩转十滴水 2013腾讯编程马拉松初赛第五场第二题
- 小明系列故事——玩转十滴水 腾讯马拉松时间模拟 HDOJ 4527
- hdu4527小明系列故事——玩转十滴水 (BFS+DFS)
- hdu 4427 玩转十滴水
- 玩转十滴水
- HDU 4528 小明系列故事――捉迷藏
- hdu 4501 小明系列故事――买年货
- HDU 4520 小Q系列故事――最佳裁判
- hdu 4501 小明系列故事――买年货 dp
- android游戏物理引擎开发——重力引擎(一)
- 用PhysicsEditor快速创建自定义Box2D刚体
- 我们了解SEO,一定要有一个正确的认识
- 回文 反序 素数
- Ping Tutorial: 15 Effective Ping Command Examples
- HDU - 4527 小明系列故事――玩转十滴水
- The Ultimate Wget Download Guide With 15 Awesome Examples
- 使用MVC结构
- Java-计算器
- MySQL 全部数据类型
- TCP/IP模型及包结构
- RMQ转LCA
- Unix Less Command: 10 Tips for Effective Navigation
- Android学习笔记1