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 ...
随机推荐
- spark1.0.0 mllib机器学习库使用初探
本文机器学习库使用的部分代码来源于spark1.0.0官方文档. mllib是spark对机器学习算法和应用的实现库,包括分类.回归.聚类.协同过滤.降维等,本文的主要内容为如何使用scala语言创建 ...
- hihocoder 162周 1323 : 回文字符串
hihocoder1323 : 回文字符串(162周) 题目链接 思路: dp; ac代码: #include<iostream> #include<cstdio> #incl ...
- iOS防止button重复点击
项目中常会遇到在按钮的点击事件中去执行一些耗时操作.如果处理不当经常会出现连续多次点击push多次的情况,造成不好的用户体验. 一种情况是用户快速连续点击,这种情况无法避免.另一种情况是点击一次后响应 ...
- ExtJs2.0学习系列(12)--Ext.TreePanel之第一式
今天开始,我们就开始一起学习TreePanel了,道个歉,上篇的代码很乱阿. 我总是喜欢用最简单的例子开始,去理解最基本的使用方法,减少对i后面高级使用的干扰! TreePanel是继承自Panel, ...
- Web前端面试题小集
一.一个页面上两个div左右铺满整个浏览器,要保证左边的div一直为100px,右边的div跟随浏览器大小变化(比如浏览器为500,右边div为400,浏览器为900,右边div为800),请写出大概 ...
- BZOJ 1032 JSOI 2007 祖码Zuma 区间DP
题目大意:依照祖玛的玩法(任意选颜色),给出一段区间.问最少用多少个球可以把全部颜色块都消除. 思路:把输入数据依照连续的块处理.保存成颜色和数量.然后用这个来DP.我们知道,一个单独的块须要两个同样 ...
- Internationalization composition diagram
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdHJvdWJsZXNob290ZXI=/font/5a6L5L2T/fontsize/400/fill/I0 ...
- Using TXMLDocument, Working with XML Nodes
Using TXMLDocument The starting point for working with an XML document is the Xml.XMLDoc.TXMLDocumen ...
- OpenERP实施记录(11):入库处理
本文是<OpenERP实施记录>系列文章的一部分. 在前面的文章中,业务部门接到沃尔玛3台联想Y400N笔记本电脑的订单,采购部门完成了补货处理.因为该产品的“最少库存规则”里面定义了“最 ...
- List of Chromium Command Line Switches(命令行开关集)——官方指定命令行更新网址
转自:http://peter.sh/experiments/chromium-command-line-switches/ There are lots of command lines which ...