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 来个优先级队列记录一下时间,暴力的搞吧
#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的更多相关文章

  1. Hdu 5336 XYZ and Drops (bfs 模拟)

    题目链接: Hdu 5336 XYZ and Drops 题目描述: 有一个n*m的格子矩阵,在一些小格子里面可能会有一些水珠,每个小水珠都有一个size.现在呢,游戏开始咯,在一个指定的空的小格子里 ...

  2. HDU 5336——XYZ and Drops——————【广搜BFS】

    XYZ and Drops Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  3. 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 ...

  4. HDU 5336 XYZ and Drops 2015 Multi-University Training Contest 4 1010

    这题的题意是给你一幅图,图里面有水滴.每一个水滴都有质量,然后再给你一个起点,他会在一開始的时候向四周发射4个小水滴,假设小水滴撞上水滴,那么他们会融合,假设质量大于4了,那么就会爆炸,向四周射出质量 ...

  5. 2015 多校赛 第四场 1010 (hdu 5336)

    Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...

  6. 2015 Multi-University Training Contest 4

    1001 Olympiad 签到题1. # include <iostream> # include <cstdio> using namespace std; ]={}; b ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. org.json.JSONObject and no properties discovered 错误解决

    自己在搭建SSM框架的时候(Spring + spring mvc + mybatis)报错内容如下: No serializer found for class org.json.JSONObjec ...

  2. 2015 UESTC 搜索专题M题 Palindromic String 马拉车算法

    Palindromic String Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/s ...

  3. acdream 1725 哗啦啦的小彭玉染色问题 离散化并查集

    哗啦啦的小彭玉染色问题 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acdream.info/problem?pid=1725 Descri ...

  4. 《pyhton学习手册》 第33章 异常编码细节

    try/except/else语句 这些语句的一般的格式如下图所示 其中try中定义了主要执行的动作.except中定义了try语句当中发生异常的处理器.else定义了没有发生异常时候的处理器. tr ...

  5. iOS开发系列--通讯录、蓝牙、

    iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用系统应用.使用系统服务: ...

  6. centos安装单机zookeeper

    1.下载zookeeper版本 wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz ...

  7. H2数据库使用 详解

    H2最完整的资料下载地址: http://download.csdn.net/detail/yixiaoping/5956595 H2数据库使用   H2数据库介绍 常用的开源数据库:H2,Derby ...

  8. delphi tcp/ip IdTCPServer1实例一

    unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...

  9. 调用 jdbcTemplate.queryForList 时出现错误 spring-org.springframework.jdbc.IncorrectResultSetColumnCountException

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  10. 嵌入式Linux开发

    嵌入式Linux的开发和研究是Linux领域研究的一个热点,目前已开发成功的嵌入式系统有一半以上都是Linux.Linux到底有什么优势,使之取得如此辉煌的成绩呢?本文分为两大部分:Linux的优点. ...