本文主要是介绍2015ACM多校对抗赛第四场 hdu 5336,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
传送门: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
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).
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.
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]);elseprintf("1 %d\n",mapt[a[i].x][a[i].y]);}return 0;
}
这篇关于2015ACM多校对抗赛第四场 hdu 5336的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!