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 ...
随机推荐
- SpringMVC 常用注解 详解
SpringMVC 常用注解 详解 SpringMVC 常用注解 1.@RequestMapping 路径映射 2.@Requ ...
- 工作中用到的git命令
1.git stash 将本地的修改藏匿,不进行commit也可切换分支 2.git stash apply 将之前藏匿的修改恢复出来 3.git cherry-pick commitId git在当 ...
- bzoj 2821 分块
分块: 先预处理,将原序列分成长度为len的许多块,计算从第i块到第j块的答案,(可以做到O(n*n/len)). 每次询问时,将询问的区间分成三部分,:左边,中间,右边,中间是尽量大的一个块区间,其 ...
- Unity 播放音频文件
Unity 播放音频文件参考代码: public void Play(string strSoundName, float autoDestroyTime = 0f, bool bLoop = fal ...
- 权限验证AuthorizeAttribute
/// <summary> /// 权限验证属性. /// </summary> public class AuthorizeExAttribute : AuthorizeAt ...
- Webpack使用指南
Webpack 是当下最热门的前端资源模块化管理和打包工具. 什么是webpack Webpack 是当下最热门的前端资源模块化管理和打包工具.它可以将许多松散的模块按照依赖和规则打包成符合生产环境部 ...
- Objective-C 关于静态方法与实例方法
objective-c中非常重要的语法知识,在此归纳总结一下. 类方法,也称静态方法,指的是用static关键字修饰的方法.此方法属类本身的方法,不属于类的某一个实例(对象).类方法中不可直接使用实例 ...
- Java常量定义需要注意事项及static作用(复习)
在任何开发语言中,都需要定义常量.在Java开发语言平台中也不例外.不过在Java常量定义的时候,跟其他语言有所不同.其有自己的特色.在这篇文章中,主要针对Java语言中定义常量的注意事项进行解析,帮 ...
- RFID Reader ICs
http://www.advanide.com/readeric.htm Low Frequency Reader ICs Manufacturer Product Frequency ISO Com ...
- NHibernate使用无状态Sessions
NHibernate 3.0 Cookbook第三章,Using stateless sessions的翻译. 当要处理大量的数据,你通常可能会使用更"底层"的API来改善性能,在 ...