2015ACM多校对抗赛第四场 hdu 5336
2015-08-01 10:30
519 查看
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5336
XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1024 Accepted Submission(s): 291
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
题意:十滴水游戏的改版。
现在某个位置有一滴即将爆炸的水滴,爆炸后,将产生四个方向的四个小水滴,每一秒只能移动一步,这些小水滴要么出了表格边界,要么和其他水滴融合,被吸收。
当融合后的值达到5的时候,又会发生爆炸,问给定n个起始水滴的T时刻后的状态。0表示爆炸了+爆炸时刻。1表示没有爆炸+最后时刻水滴大小。
宽搜就行了,用优先队列维护,并标记。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<queue> using namespace std; #define sf scanf const int d[4][2]={1,0,0,1,-1,0,0,-1}; struct node{ int t,x,y,d; bool operator<(const node &a)const{return t>a.t;} }; struct point{ int x,y; }a[105]; int r,c,n,T; priority_queue<node> que; int mapt[102][102]; int ans[101][101]; bool legel(int x,int y){return x>0&&x<=r&&y>0&&y<=c;} void addque(node p) { for(int i = 0;i<4;i++) { int xx = p.x + d[i][0]; int yy = p.y + d[i][1]; while(legel(xx,yy)&&mapt[xx][yy] == 0) {xx+=d[i][0];yy+=d[i][1];} //cout<<xx<<" "<<yy<<endl; if(mapt[xx][yy] != 0) { //cout<<xx<<","<<yy<<":"<<abs(xx+yy-p.x-p.y)+p.t<<endl; que.push(node{abs(xx+yy-p.x-p.y)+p.t,xx,yy,i}); } } } int main() { while(~sf("%d%d%d%d",&r,&c,&n,&T)) { memset(mapt,0,sizeof mapt); memset(ans,0,sizeof ans); for(int i = 0;i<n;i++) { int x,y,z; sf("%d%d%d",&x,&y,&z); mapt[x][y] = z; a[i] = point{x,y}; } int x,y; sf("%d%d",&x,&y); while(!que.empty()) que.pop(); addque(node{0,x,y,0}); while(!que.empty()) { node p = que.top(); //cout<<p.t<<":"<<p.x<<","<<p.y<<"----------"<<endl; que.pop(); if(p.t>T) continue; if(mapt[p.x][p.y]<=4) { mapt[p.x][p.y]++; if(mapt[p.x][p.y]==5) { addque(p); ans[p.x][p.y] = p.t; } } else { if(ans[p.x][p.y] != p.t) { int xx = p.x + d[p.d][0]; int yy = p.y + d[p.d][1]; while(legel(xx,yy)&&mapt[xx][yy] == 0) {xx+=d[p.d][0];yy+=d[p.d][1];} if(mapt[xx][yy] != 0) { // cout<<xx<<","<<yy<<":"<<abs(xx+yy-p.x-p.y)+p.t<<endl; que.push(node{abs(xx+yy-p.x-p.y)+p.t,xx,yy,p.d}); } } } } for(int i =0;i<n;i++) if(ans[a[i].x][a[i].y]!=0) printf("0 %d\n",ans[a[i].x][a[i].y]); else printf("1 %d\n",mapt[a[i].x][a[i].y]); } return 0; }
相关文章推荐
- 搜狗百度360市值齐跌:搜索引擎们陷入集体焦虑?
- 本人即将筹备败家日志,敬请期待!
- IE:使用搜索助手
- C++深度优先搜索的实现方法
- 基于文本的搜索
- php实现搜索一维数组元素并删除二维数组对应元素的方法
- 使用Sphinx对索引进行搜索
- asp 多关键词搜索的简单实现方法
- C#使用foreach语句搜索数组元素的方法
- JavaScript中数组的排序、乱序和搜索实现代码
- C#编程实现Excel文档中搜索文本内容的方法及思路
- sqlserver中在指定数据库的所有表的所有列中搜索给定的值
- 可以用来搜索当前页面内容的js代码
- 全文搜索和替换
- javascript搜索自动提示功能的实现第1/3页
- mysql 模糊搜索的方法介绍
- 基于ASP.NET的lucene.net全文搜索实现步骤
- 做个自己站内搜索引擎
- PHP查找与搜索数组元素方法总结
- C语言按关键字搜索文件夹中文件的方法