HDU 5336 XYZ and Drops
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
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).
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.
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 来个优先级队列记录一下时间,暴力的搞吧#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>
#include<string>
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
using namespace std;
const ll maxn=105;
int T,n,m,t,f[maxn][maxn],x,y,a[maxn],b[maxn],c[maxn][maxn]; struct point
{
int x,y,z,t,now;
point(){}
point(int x,int y,int z,int t,int now):
x(x),y(y),z(z),t(t),now(now) {};
bool operator <(const point &a) const
{
return now+t>a.now+a.t;
}
}; int get(int x,int y,int d)
{
if (d&1)
{
if (d==1)
{
for (int i=y+1;i<=m;i++)
if (f[x][i]) return i-y;
return 0;
}
else
{
for (int i=y-1;i>=1;i--)
if (f[x][i]) return y-i;
return 0;
}
}
else
{
if (d==0)
{
for (int i=x-1;i>=1;i--)
if (f[i][y]) return x-i;
return 0;
}
else
{
for (int i=x+1;i<=n;i++)
if (f[i][y]) return i-x;
return 0;
}
}
} int main()
{
//scanf("%d",&T);
while (~scanf("%d%d%d%d",&n,&m,&t,&T))
{
memset(f,0,sizeof(f));
memset(c,0,sizeof(c));
for (int i=1;i<=t;i++)
{
scanf("%d%d",&x,&y);
a[i]=x; b[i]=y;
scanf("%d",&f[x][y]);
}
scanf("%d%d",&x,&y);
priority_queue<point> p;
for (int i=0;i<4;i++)
{
int k=get(x,y,i);
if (k>0) p.push(point(x,y,i,k,0));
}
while (!p.empty())
{
point tp,q=p.top(); p.pop(); for (;;p.pop())
{
if (p.empty()) break;
tp=p.top();
if(tp.now+tp.t!=q.now+q.t) break;
int k=get(tp.x,tp.y,tp.z);
if (!k) continue;
if (k!=tp.t) p.push(point(tp.x,tp.y,tp.z,k,tp.now));
else
{
if (k+tp.now>T) break;
if (tp.z==0) x=tp.x-k,y=tp.y;
if (tp.z==1) x=tp.x,y=tp.y+k;
if (tp.z==2) x=tp.x+k,y=tp.y;
if (tp.z==3) x=tp.x,y=tp.y-k;
f[x][y]++;
}
}
int k=get(q.x,q.y,q.z);
if (k)
if (k!=q.t) p.push(point(q.x,q.y,q.z,k,q.now));
else
{
if (k+q.now>T) break;
if (q.z==0) x=q.x-k,y=q.y;
if (q.z==1) x=q.x,y=q.y+k;
if (q.z==2) x=q.x+k,y=q.y;
if (q.z==3) x=q.x,y=q.y-k;
f[x][y]++;
}
for(int i=1;i<=t;i++)
{
x=a[i]; y=b[i];
if (f[x][y]>4)
{
f[x][y]=0;
c[x][y]=q.t+q.now;
for (int j=0;j<4;j++)
{
int u=get(x,y,j);
if (u>0) p.push(point(x,y,j,u,q.t+q.now));
}
}
}
}
for (int i=1;i<=t;i++)
{
if (f[a[i]][b[i]]) printf("1 %d\n",f[a[i]][b[i]]);
else printf("0 %d\n",c[a[i]][b[i]]);
}
}
return 0;
}
HDU 5336 XYZ and Drops的更多相关文章
- Hdu 5336 XYZ and Drops (bfs 模拟)
题目链接: Hdu 5336 XYZ and Drops 题目描述: 有一个n*m的格子矩阵,在一些小格子里面可能会有一些水珠,每个小水珠都有一个size.现在呢,游戏开始咯,在一个指定的空的小格子里 ...
- HDU 5336——XYZ and Drops——————【广搜BFS】
XYZ and Drops Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 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 ...
- HDU 5336 XYZ and Drops 2015 Multi-University Training Contest 4 1010
这题的题意是给你一幅图,图里面有水滴.每一个水滴都有质量,然后再给你一个起点,他会在一開始的时候向四周发射4个小水滴,假设小水滴撞上水滴,那么他们会融合,假设质量大于4了,那么就会爆炸,向四周射出质量 ...
- 2015 多校赛 第四场 1010 (hdu 5336)
Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...
- 2015 Multi-University Training Contest 4
1001 Olympiad 签到题1. # include <iostream> # include <cstdio> using namespace std; ]={}; b ...
- HDU 3213 Box Relations(拓扑排序构造)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3231 题意:有n个长方体,四种限制条件.(1)I x y x和y有相交:(2)X/Y/Z x y x ...
- HDU 4282 A very hard mathematic problem 二分
A very hard mathematic problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sh ...
- HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)
Friends and Enemies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
随机推荐
- 清北学堂学习总结 day1 数据结构 练习
1.二叉搜索树 STL set直接做就可以了 2.树状数组+差分数列: codevs 1081 线段树练习 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Maste ...
- 如何判断c语言的变量类型
变量三要素: 一个变量有三个基本的要素,变量的名称,变量的类型,变量的值.所以int a = 10; 变量名为a,变量的存储类型为int型,变量的值为10. 变量还有一些属性如作用范围和存储类型. 变 ...
- Android 动画——属性动画Property Animation
Android在3.0之前只提供了两种动画:View Animation .Drawable Animation .也就是我们在<Android 动画——Frame Animation与Twee ...
- setTimeOut传參数
function blink(e_Id, second) {var soccer = document.getElementById(e_Id); soccer.style.visibility = ...
- combogrid 摘要
可装载组合框 - ComboBox 继承自$.fn.combo.defaults,通过$.fn.combobox.defaults覆盖默认值 combobox显示的是一个可以编辑的文本框和一个下拉列表 ...
- linux automake 交叉编译
. ├── aclocal.m4 ├── autoscan.log ├── config.log ├── config.status ├── configure ├── configure.in ├─ ...
- [Android Pro] Android7.0系统 关于Android获取流量计数TrafficStats.getUidRxBytes(uid)和TrafficStats.getUidTxBytes(uid)返回-1解决方案
reference : http://blog.csdn.net/zhangyong7112/article/details/54574214 最近一个关于流量的项目在Android7.0系统的手机上 ...
- iOS:CoreData数据库的使用一(创建单个数据库表)
CoreData数据库框架:mac系统自带的数据库,它是苹果公司对sqlite进行封装而来的,既提供了对数据库的主要操作,也提供了具体的视图关系模型. 需要用到三个对象: 1•Managed Obje ...
- 如何在SharePoint的列表中使用通配符来filter出ListItem?
一个朋友问我这样一个问题, 他想要快速从SharePoint的文档库中filter出来名字中先带有一个Q, 接着一些其他的字符, 后面再跟着有一个数字20这样的文件. 第一个想法就是修改Share ...
- java页面url传值中文编码&解码
URL参数中有中文值,传到服务端,在用request.getParameter()方法,得到的常常会是乱码. 这将涉及到字符解码操作,我们在应用中常常会用new String(fieldType.ge ...