XYZ and Drops

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 505    Accepted Submission(s): 122

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 Tseconds, 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
 
Author
XJZX
 
Source
 
解题:直接模拟爆炸情况。。。
 
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int dir[][] = {-,,,-,,,,};
int mp[maxn][maxn],r,c,n,T,x,y;
struct waterdrop {
int x,y,sz,btime;
bool crack;
waterdrop(int a = ,int b = ,int c = ,int d = ) {
x = a;
y = b;
sz = c;
btime = d;
}
} wp[maxn];
struct drop {
int x,y,time,o;
drop(int a = ,int b = ,int c = ,int d = ) {
x = a;
y = b;
time = c;
o = d;
}
};
queue<drop>q;
bool isIn(int x,int y) {
return x > && x <= r && y > && y <= c;
}
void bfs() {
for(int i = ; i < ; ++i)
q.push(drop(x,y,,i));
while(!q.empty()) {
drop cur = q.front();
q.pop();
if(cur.time >= T) return;
int nx = cur.x + dir[cur.o][];
int ny = cur.y + dir[cur.o][];
if(!isIn(nx,ny)) continue;
int idx = mp[nx][ny];
if(idx == - || wp[idx].crack && wp[idx].btime != cur.time+) q.push(drop(nx,ny,cur.time+,cur.o));
else if(!wp[idx].crack) {
wp[idx].sz++;
if(wp[idx].sz > ) {
wp[idx].crack = true;
wp[idx].btime = cur.time+;
for(int k = ; k < ; ++k)
q.push(drop(wp[idx].x,wp[idx].y,cur.time+,k));
}
}
}
}
int main() {
while(~scanf("%d%d%d%d",&r,&c,&n,&T)) {
memset(mp,-,sizeof mp);
while(!q.empty()) q.pop();
for(int i = ; i < n; ++i) {
scanf("%d%d%d",&wp[i].x,&wp[i].y,&wp[i].sz);
wp[i].crack = false;
mp[wp[i].x][wp[i].y] = i;
if(wp[i].sz > ) {
wp[i].crack = true;
wp[i].btime = ;
for(int k = ; k < ; ++k)
q.push(drop(wp[i].x,wp[i].y,,k));
}
}
scanf("%d%d",&x,&y);
bfs();
for(int i = ; i < n; ++i)
printf("%d %d\n",!wp[i].crack,wp[i].crack?wp[i].btime:wp[i].sz);
}
return ;
}

2015 Multi-University Training Contest 4 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 2015 Multi-University Training Contest 4 1010

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

  3. HDU 5336 XYZ and Drops

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

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

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

  5. 2015 Multi-University Training Contest 8 hdu 5390 tree

    tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...

  6. 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!

    Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID:  ...

  7. 2015 Multi-University Training Contest 8 hdu 5385 The path

    The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...

  8. 2015 Multi-University Training Contest 3 hdu 5324 Boring Class

    Boring Class Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  9. 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

    RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

随机推荐

  1. 如何让select中的滚动条自动定位到框中选中项的位置

    document.getElementById("hidScrollTop").value = document.getElementById("slcYZYongFa& ...

  2. 光盘文件的挂载和yum源配置

    一.挂载光盘文件 1.将光盘推入 2.新建挂载点 mkdir /mnt/cdrom 3.挂载 3.1临时挂载 mount /dev/dcrom /mnt/cdrom 或者 mount  –t  iso ...

  3. 紫书 例题8-1 UVa 120(构造法)

    #include<cstdio> #include<iostream> #include<sstream> #include<algorithm> #d ...

  4. 调整mysql数据库最大连接数

    1.查看mariadb数据库最大连接数,默认为151 MariaDB [(none)]> show variables like 'max_connections'; +------------ ...

  5. tp框架,addAll方法报错,返回false

    tp框架的批量添加addAll($data)方法很实用,但是注意,数据数组的数据结构要保持一致,不然会返回false.

  6. Objective-C 和 Core Foundation 对象相互转换

    iOS同意Objective-C 和 Core Foundation 对象之间能够轻松的转换: CFStringRef aCFString = (CFStringRef)aNSString; NSSt ...

  7. C++ OTL MySQL(Windows/Linux) V8.1

    Windows每秒钟10000条以上插入:Linux每秒插入300条以上.Q269752451 输出截图: Linux输出: Windows输出: 有须要的联系 QQ 3508551694 water ...

  8. Oracle性能分析1:开启SQL跟踪和获取trace文件

    当Oracle查询出现效率问题时,我们往往须要了解问题所在,这样才干针对问题给出解决方式.Oracle提供了SQL运行的trace信息,当中包括了SQL语句的文本信息.一些运行统计,处理过程中的等待, ...

  9. 关于Servo项目中Rust代码行数的数据来源

    我两个月之前的一篇博客<为什么我说Rust是靠谱的编程语言>(下面简称原文),在当中"6. 两个半大型成功案例"一节.我以前写道: Servo: 下一代浏览器渲染引擎( ...

  10. 整数翻转C++实现 java实现 leetcode系列(七)

    给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: ...