hdu5336XYZ and Drops
题意:给出r*c的网格,有的网格为空。有的有水。再给出一个爆炸点,从这个点向四周爆出四个水滴,若碰到水则融为一体,若碰到其它水滴直接跑过去互不影响。每秒可跑一格,若水中水滴数量超过4则爆开。问T秒后网格的状态是如何的。
做法:因为数据有点多,直接用set优化bfs一次走一步的过程。变成一次走多步就可以。
- #include<map>
- #include<string>
- #include<cstring>
- #include<cstdio>
- #include<cstdlib>
- #include<cmath>
- #include<queue>
- #include<vector>
- #include<iostream>
- #include<algorithm>
- #include<bitset>
- #include<climits>
- #include<list>
- #include<iomanip>
- #include<stack>
- #include<set>
- using namespace std;
- int num[110][110];
- set<int>sr[110],sc[110];
- int r,c,T;
- bool beyond(int tr,int tc)
- {
- return tr<1||tc<1||tr>r||tc>c;
- }
- struct point
- {
- int tr,tc,flag;
- point(){}
- point(int tr,int tc,int flag)
- {
- this->tr=tr;
- this->tc=tc;
- this->flag=flag;
- }
- }hehe[110];
- vector<point>bx;
- bool vis[110][110];
- void gao(int tr,int tc,int flag,int cnt)
- {
- if(!beyond(tr,tc)&&!vis[tr][tc])
- {
- if(num[tr][tc]>0)
- {
- num[tr][tc]++;
- if(num[tr][tc]>4)
- {
- sr[tr].erase(tc);
- sc[tc].erase(tr);
- num[tr][tc]=-cnt;
- bx.push_back(point(tr,tc,0));
- vis[tr][tc]=1;
- }
- }
- else
- bx.push_back(point(tr,tc,flag));
- }
- }
- void work()
- {
- set<int>::iterator it;
- int cnt=0,p=0;
- while(1)
- {
- int len=bx.size(),mn=INT_MAX;
- if(p==len)
- return;
- for(int i=p;i<len;i++)
- {
- point t=bx[i];
- int tr=t.tr,tc=t.tc,flag=t.flag;
- if(flag==0||flag==1)
- {
- it=sc[tc].lower_bound(tr);
- if(it!=sc[tc].begin())
- {
- it--;
- mn=min(mn,tr-*it);
- }
- }
- if(flag==0||flag==2)
- {
- it=sc[tc].upper_bound(tr);
- if(it!=sc[tc].end())
- mn=min(mn,*it-tr);
- }
- if(flag==0||flag==3)
- {
- it=sr[tr].lower_bound(tc);
- if(it!=sr[tr].begin())
- {
- it--;
- mn=min(mn,tc-*it);
- }
- }
- if(flag==0||flag==4)
- {
- it=sr[tr].upper_bound(tc);
- if(it!=sr[tr].end())
- mn=min(mn,*it-tc);
- }
- }
- if(cnt+mn>T)
- return;
- cnt+=mn;
- memset(vis,0,sizeof(vis));
- for(int i=p;i<len;i++)
- {
- point t=bx[i];
- int tr=t.tr,tc=t.tc,flag=t.flag;
- if(flag==0||flag==1)
- {
- tr-=mn;
- gao(tr,tc,1,cnt);
- tr+=mn;
- }
- if(flag==0||flag==2)
- {
- tr+=mn;
- gao(tr,tc,2,cnt);
- tr-=mn;
- }
- if(flag==0||flag==3)
- {
- tc-=mn;
- gao(tr,tc,3,cnt);
- tc+=mn;
- }
- if(flag==0||flag==4)
- {
- tc+=mn;
- gao(tr,tc,4,cnt);
- tc-=mn;
- }
- }
- p=len;
- }
- }
- int main()
- {
- int n;
- while(scanf("%d%d%d%d",&r,&c,&n,&T)!=EOF)
- {
- for(int i=1;i<=r;i++)
- sr[i].clear();
- for(int i=1;i<=c;i++)
- sc[i].clear();
- memset(num,0,sizeof(num));
- for(int i=0;i<n;i++)
- {
- int t;
- scanf("%d%d%d",&hehe[i].tr,&hehe[i].tc,&t);
- sr[hehe[i].tr].insert(hehe[i].tc);
- sc[hehe[i].tc].insert(hehe[i].tr);
- num[hehe[i].tr][hehe[i].tc]=t;
- }
- int tr,tc;
- scanf("%d%d",&tr,&tc);
- bx.clear();
- bx.push_back(point(tr,tc,0));
- work();
- for(int i=0;i<n;i++)
- {
- tr=hehe[i].tr;
- tc=hehe[i].tc;
- int t=num[tr][tc];
- if(t<0)
- printf("0 %d\n",-t);
- else
- printf("1 %d\n",t);
- }
- }
- }
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 414 Accepted Submission(s): 101
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
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).
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.
4 4 5 10 2 1 4 2 3 3 2 4 4 3 1 2 4 3 4 4 4
0 5 0 3 0 2 1 3 0 1
hdu5336XYZ and Drops的更多相关文章
- HDU5336-XYZ and Drops-模拟
模拟水珠那个游戏. 小水珠超过边界会消失. 会有两个水珠同时到达一个size=4大水珠的情况.要移动完统一爆炸 #include <vector> #include <cstdio& ...
- HDU 5336 XYZ and Drops
Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...
- HDU 5336——XYZ and Drops——————【广搜BFS】
XYZ and Drops Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- Hdu 5336 XYZ and Drops (bfs 模拟)
题目链接: Hdu 5336 XYZ and Drops 题目描述: 有一个n*m的格子矩阵,在一些小格子里面可能会有一些水珠,每个小水珠都有一个size.现在呢,游戏开始咯,在一个指定的空的小格子里 ...
- 2015 Multi-University Training Contest 4 hdu 5336 XYZ and Drops
XYZ and Drops Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- Huge Packet Drops (Tx drops) Observed on NetScaler
Huge Packet Drops (Tx drops) Observed on NetScaler 来源 https://support.citrix.com/article/CTX215843 ...
- Django Drops
1.Django Intro 2.Django Install (1) PIP安装 sudo apt-get isntall python-pip sudo pip install Django (2 ...
- HDU 5336 XYZ and Drops 2015 Multi-University Training Contest 4 1010
这题的题意是给你一幅图,图里面有水滴.每一个水滴都有质量,然后再给你一个起点,他会在一開始的时候向四周发射4个小水滴,假设小水滴撞上水滴,那么他们会融合,假设质量大于4了,那么就会爆炸,向四周射出质量 ...
- 全网最全乌云drops文章下载(epub)
前几天搞得epub格式的,为了方便kindle才做的,没想到站关了. 链接: http://pan.baidu.com/s/1eRIoJC2 密码: b6aq
随机推荐
- 路飞学城Python-Day14(practise)
本章总结 练习题 1.logging模块有几个日志级别? 5个,按级别从高到低分别是 CRITICAL(灾难)>ERROR(错误)>WARNING(警示)>INFO(信息)>D ...
- BZOJ 3129 [SDOI2013]方程 (拓展Lucas)
题目大意:给定一个方程$X_{1}+X_{2}+X_{3}+X_{4}+...+X_{n}=M$,$\forall X_{i}<=A_{i} (i<=n1)$ $\forall X_{i} ...
- Python 线程高级篇 threading 模块的使用
创建一个tread实例,给他传一个函数 #!/usr/bin/python import threading from time import * loops =[4,2] def loop (nlo ...
- 比较排序算法(PHP)
冒泡排序 两两比较相邻记录的关键字,如果反序则交换,大的数字往下沉,一直到最大的出现在数组最后 function swap(&$x, &$y) { $temp = $x; $x = $ ...
- 紫书 习题 8-23 UVa 1623 (set妙用 + 贪心)
这道题我是从样例中看出思路了 2 4 0 0 1 1 看这组数据, 输出的是No, 为什么呢?因为两个1之间没有神龙喝水, 所以一定会有水灾. 然后就启发了我,两次同一个湖的降水之间必须至少有一次神龙 ...
- Oracle with as 嵌套
oracle with as可以理解为临时视图,可以极大的简化sql语句,并且支持嵌套使用. With c3 As(Select * From v_tr_daily Where p_date=to_ ...
- 批量修改文件的编码格式至UTF-8
批量修改文件的编码格式至UTF-8 学习了: https://jingyan.baidu.com/article/e8cdb32b47a1ea37042bad11.html http://blog.c ...
- ubuntu 14.04 桌面版关闭图形界面
ubuntu 14.04 桌面版关闭图形界面 问题: 怎样将ubuntu14.04设置为文本模式启动? 解决方式: 改动改GRUB 的配置文件(不建议直接改 grub.conf) $sudo vim ...
- BAPC2014 K&&HUNNU11591:Key to Knowledge(中途相遇法)
题意: 有N个学生.有M题目 然后相应N行分别有一个二进制和一个整数 二进制代表该同学给出的每道题的答案.整数代表该同学的答案与标准答案相符的个数 要求推断标准答案有几个,假设标准答案仅仅有一种.则输 ...
- iOS自动布局高级用法 && 纯代码约束写法
本文主要介绍几个我遇到的总结的高级用法(当然我相信肯定有不少比这还高级的). 简单的storyboard中上下左右约束,固定宽高啥的用法在这里就不做赘述了. autolayout自动布局是iOS6以后 ...