题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5336

题面:

XYZ and Drops

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 725    Accepted Submission(s): 201

Problem Description
XYZ is playing an interesting game called "drops". It is played on a r∗c grid. Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property "size". The waterdrop cracks when its size is larger than 4, and produces 4 small drops moving towards 4 different directions (up, down, left and right).

In every second, every small drop moves to the next cell of its direction. It is possible that multiple small drops can be at same cell, and they won't collide. Then for each cell occupied by a waterdrop, the waterdrop's size increases by the number of the small drops in this cell, and these small drops disappears.

You are given a game and a position (x, y), before the first second there is a waterdrop cracking at position (x, y). XYZ wants to know each waterdrop's status after T seconds, can you help him?

1≤r≤100, 1≤c≤100, 1≤n≤100, 1≤T≤10000

Input
The first line contains four integers r, c, n and T. n stands for the numbers of waterdrops at the beginning.
Each line of the following n lines contains three integers xi, yi, sizei, meaning that the i-th waterdrop is at position (xi, yi) and its size is sizei. (1≤sizei≤4)
The next line contains two integers x, y.

It is guaranteed that all the positions in the input are distinct.

Multiple test cases (about 100 cases), please read until EOF (End Of File).

Output
n lines. Each line contains two integers Ai, Bi:
If the i-th waterdrop cracks in T seconds, Ai=0, Bi= the time when it cracked.
If the i-th waterdrop doesn't crack in T seconds, Ai=1, Bi= its size after T seconds.
Sample Input
4 4 5 10 2 1 4 2 3 3 2 4 4 3 1 2 4 3 4 4 4
Sample Output
0 5 0 3 0 2 1 3 0 1
Author
XJZX
Source
2015 Multi-University Training Contest 4

解题:
    比赛的时候,卡在Walk out那题上了,看这道题又觉得题意不清晰,又怕超时,就没敢做,后面一个小时都在发呆,其实以后应该充分利用时间,不要太高估题目。往往最后一个小时才是最关键的。另外一只队伍最后一小时出了3题。
    题目意思是,在给定的方格中的某些位置,有一些水团,当新加入水珠时,如果该水团的体积大于4,那么它就会变成4个体积为1的水珠,朝上下左右四个方向去。每1秒移动1格,当新水珠加入水团时,水团可能会因体积大于4而爆炸。还有,如果多个水珠同时到达一个格子,而该格子没有水团,那么这些水珠将继续前行,如果出了边界,便消失。
    用bfs模拟水珠的运动,如果水珠加入一个水团,那么该水团的体积加一,并判断是否大于4,大于则分解成4个小水珠加入队列,并将该点体积清零。如果不大于,那么只是单纯的将体积加一,该水珠也就加入了水团,不再运动。同时需注意,因为可能一个水珠先到达水团,该水团就分解了,后续队列中又一水珠到达该处,如果之前分解的时候,不加标记,那么就会朝现在的水珠方向,多出一颗水珠,所以要加一个标记(用crack非零标记)。
    一个位置是不可能分解两次的,因为只有初始有水团的地方,才能吸收水珠,进而分解,所以也无需考虑crack是否会重复或覆盖的问题。

总结:
   要相信自己,基本上100人可以做的题目,那么都可以去尝试,也不用死抠复杂度,只要不是明显不可以的,而手头又空着,无题可做,那么就可以去大胆地敲。这题的模拟,其实比赛的时候觉得并不是很难,但因为过得只有100人,怕暴力模拟会超时,所以没做,事实证明46ms,实属遗憾啊!

代码:

#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
using namespace std;
int r,c,n,t,tx,ty;
//四个方向
int d[4][2]={0,1,-1,0,0,-1,1,0};
//运动的小水珠的方向,坐标和时间
struct node
{int dir,x,y,t;
};
//判断是否在边界内
bool Inside(int x,int y)
{if(x>=1&&x<=r&&y>=1&&y<=c)return true;return false;
}
//存储水团的位置
struct drop
{int x,y;
}store[105];
queue <node> qe;
//map记容量
int  map[105][105];
//crack记分解时间
int crack[105][105];
//模拟水珠运动
void bfs()
{int dir,ti,xx,yy;node tmp;while(!qe.empty()){//取当前节点tmp=qe.front();qe.pop();tx=tmp.x;ty=tmp.y;dir=tmp.dir;ti=tmp.t;//如果该点有水团if(map[tx][ty]){//体积加1map[tx][ty]++;//大于4,分解if(map[tx][ty]>4){//记录分解时间crack[tx][ty]=ti;map[tx][ty]=0;for(int i=0;i<4;i++){//四个方向xx=tx+d[i][0];yy=ty+d[i][1];//在边界内if(Inside(xx,yy)){tmp.x=xx;tmp.y=yy;tmp.t=ti+1;tmp.dir=i;//在时间T内if(tmp.t<=t)qe.push(tmp);}}}}//该点原本就没有水团或者水团已经分解,但不是刚刚分解的,去除那个已经弹出的水珠的情况else if(crack[tx][ty]!=ti){xx=tx+d[dir][0];yy=ty+d[dir][1];if(Inside(xx,yy)){tmp.x=xx;tmp.y=yy;tmp.t=ti+1;tmp.dir=dir;if(tmp.t<=t)qe.push(tmp);}}}
}
int main()
{int x,y,v;node tmp;while(~scanf("%d%d%d%d",&r,&c,&n,&t)){memset(map,0,sizeof(map));memset(crack,0,sizeof(crack));//读入for(int i=0;i<n;i++){scanf("%d%d%d",&store[i].x,&store[i].y,&v);map[store[i].x][store[i].y]=v;}scanf("%d%d",&x,&y);//初始点分解for(int i=0;i<4;i++){tx=x+d[i][0];ty=y+d[i][1];if(Inside(tx,ty)){tmp.x=tx;tmp.y=ty;tmp.t=1;tmp.dir=i;qe.push(tmp);}}//模拟bfs();//输出for(int i=0;i<n;i++){if(crack[store[i].x][store[i].y])printf("0 %d\n",crack[store[i].x][store[i].y]);elseprintf("1 %d\n",map[store[i].x][store[i].y]);}} return 0;
}

HDU 5336 XYZ and Drops (模拟+搜索,详解)相关推荐

  1. HDU 5336 XYZ and Drops(模拟十滴水游戏 BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5336 Problem Description XYZ is playing an interestin ...

  2. java测试模拟网页点击,httpunit爬虫模拟搜索详解与实战

    一.WEB测试工具介绍 httpunit是一个可以模拟浏览器的集成工具,它可以让你在不需要浏览器的情况下模拟浏览器的浏览行为,该工具是junit测试工具下面的一个子框架,主要用来做web端测试使用,它 ...

  3. 蓝桥杯 Java B组 省赛决赛模拟赛 详解及小结汇总+题目下载【2013年(第4届)~2021年(第12届)】

    蓝桥杯 Java B组 省赛决赛模拟赛 详解及小结汇总+题目下载[2013年(第4届)~2021年(第12届)] 百度网盘-CSDN蓝桥杯资料(真题PDF+其它资料)   提取码:6666 2013年 ...

  4. ElasticSearch最全详细使用教程:入门、索引管理、映射详解、索引别名、分词器、文档管理、路由、搜索详解...

    墨墨导读:之前我们分享了ElasticSearch最全详细使用教程:入门.索引管理.映射详解,本文详细介绍ElasticSearch的索引别名.分词器.文档管理.路由.搜索详解. 一.索引别名 1. ...

  5. 综合模拟试题计算机指南,2018年全国硕士研究生入学统一考试计算机科学与技术学科联考计算机学科专业基础综合历年真题及模拟试题详解...

    2018年全国硕士研究生入学统一考试计算机科学与技术学科联考计算机学科专业基础综合历年真题及模拟试题详解本站小编 辅仁网/2017-06-21 下载地址:http://free.100xuexi.co ...

  6. c++深度优先搜索详解

    目录 哈喽 dfs乃何物? DFS算法过程: dfs基本框架 题目1 代码 题目2 n-皇后问题 代码 寻路 代码 最后 哈喽 各位好 晚上从沙发上起来,端坐在电脑前 我大抵是无聊了 思前想后,我还是 ...

  7. elasticsearch最全详细使用教程:入门、索引管理、映射详解、索引别名、分词器、文档管理、路由、搜索详解

    一.快速入门 1. 查看集群的健康状况 http://localhost:9200/_cat http://localhost:9200/_cat/health?v 说明:v是用来要求在结果中返回表头 ...

  8. Firefox 2010:火狐魔镜搜索详解

    (本文由北京谋智网络技术有限公司提供) 近日,火狐中国版2010.1发布了,此版本的一大特色是:火狐魔镜v3.本文跟大家介绍一下在火狐魔镜中的搜索功能,继而也希望作为一个用户体验和交互的题目来跟大家分 ...

  9. 深度优先搜索详解 C++实现

    DFS 全文大概四千字左右,如果您初学DFS相信会对您会有很大的帮助,能力有限,很多术语不够专业,理解万岁 二叉树的深度优先搜索 二叉树的概念这里就不细谈了 使用数组来存储二叉树,根结点从1开始(方便 ...

  10. 【蓝桥杯真题】地宫取宝(搜索-记忆化搜索详解)

    链接 [蓝桥杯][2014年第五届真题]地宫取宝 题目描述 X 国王有一个地宫宝库.是 n x m 个格子的矩阵.每个格子放一件宝贝.每个宝贝贴着价值标签. 地宫的入口在左上角,出口在右下角. 小明被 ...

最新文章

  1. C语言实现九九乘法表共9行9列,重点考察for循环的掌握情况!
  2. Android开发之动画(转)
  3. (王道408考研操作系统)第四章文件管理-第二节3:减少延迟时间的方法
  4. android意图实验报告,Activity 常见的意图整理
  5. linux cat时间段,linux – cat / dev / urandom的输出是多么临时
  6. 如何让 MSN 与应用系统紧密集成起来?
  7. 深度学习实践指南(四)—— 一个典型的深度学习的实践流程
  8. ubuntu12.04升级svn到 1.7
  9. 阿里云mysql可视化_MySql可视化工具MySQL Workbench使用教程
  10. 02. Win32 API简介
  11. 联想计算机型号吧,lenovo全系列联想笔记本电脑型号对照表
  12. Forth语言简明教程
  13. MongoDB与物联网应用讲座
  14. remix下ballot.sol调试
  15. 阿里云ECS服务器修复漏洞
  16. 祝萍:后疫情时代医美运营要以顾客体验为中心
  17. 实践任务1:利用 HBuilderX制作产品展示模块+实践任务2:利用 HBuilderX制作公司网站首页+实践任务3: 利用 HBuilderX制作公司网站首页实现固定侧边菜单
  18. Avazu_ctr_prediction 数据集之Avazu_x4.zip介绍
  19. 策略系列篇(一)—小市值轮动
  20. 6.C语言 二维数组

热门文章

  1. 创意分析及优化技巧 — 百度推广
  2. RAID1与RAID0的区别
  3. JAVA修炼秘籍第三章《绝地反击》
  4. 图像处理系列——图像融合之加权平均(WA)
  5. 美丽的秋天秋天是多么美丽呀!
  6. 洛谷——P1957 口算练习题
  7. 分词:词性标注北大标准
  8. 计算机表格常用根式,平方根表
  9. Python:读写txt、xlsx、mat、csv、yaml、npy、npz文件
  10. linux下分配磁盘空间,linux如何分配磁盘空间