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. pip常见用法汇总

    1.pip安装 yum -y install epel-release && yum -y install python-pip 2.pip安装软件 (1)安装单个软件:pip ins ...

  2. [剑指offer] 8+9. 跳台阶+变态跳台阶 (递归 时间复杂度)

    跳台阶是斐波那契数列的一个典型应用,其思路如下: # -*- coding:utf-8 -*- class Solution: def __init__(self): self.value=[0]*5 ...

  3. [剑指offer] 7. 斐波那契数列 (递归 时间复杂度)

    简介: 杨辉三角每条斜线上的数之和就构成斐波那契数列. 思路: 参考文章:https://mp.weixin.qq.com/s?src=11&timestamp=1551321876& ...

  4. STM32 SPI 发送第一个数据不成功问题

    STM32的标准库,跟HAL库都是很实用的, 在使用SPI库的过程中一定要注意时序的问题. 我在调试SPI过程中,调试了两个IC,都是用HAL库, 第一个IC没出问题,第二个IC出现了第一次发送数据不 ...

  5. Jquery学习总结(4)——高效Web开发的10个jQuery代码片段

    在过去的几年中,jQuery一直是使用最为广泛的JavaScript脚本库.今天我们将为各位Web开发者提供10个最实用的jQuery代码片段,有需要的开发者可以保存起来. 1.检测Internet ...

  6. 一个简单搜索引擎的搭建过程(Solr+Nutch+Hadoop)

    最近,因为未来工作的需要,我尝试安装部署了分布式爬虫系统Nutch,并配置了伪分布式的Hadoop来存储爬取的网页结果,用solr来对爬下来的网页进行搜索.我主要通过参考网上的相关资料进行安装部署的. ...

  7. JavaWeb初学者session的使用

    使用request对象的getSession()获取session,如果session不存在则创建一个 HttpSession session = request.getSession();将数据存储 ...

  8. 洛谷 P1301 魔鬼之城

    P1301 魔鬼之城 题目描述 在一个被分割为N*M个正方形房间的矩形魔鬼之城中,一个探险者必须遵循下列规则才能跳跃行动.他必须从(1, 1)进入,从(N, M)走出:在每一房间的墙壁上都写了一个魔法 ...

  9. leetcode笔记:Find Median from Data Stream

    一. 题目描写叙述 Median is the middle value in an ordered integer list. If the size of the list is even, th ...

  10. Test Precisely and Concretely

    Test Precisely and Concretely Kevlin Henney IT IS IMPORTANT TO TEST for the desired, essential behav ...