hdu5336 XYZ and Drops (关于十滴水游戏的模拟)

XYZ and Drops

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


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?

1r100 1c100 1n100 1T10000
 

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 . ( 1sizei4 )
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 <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
struct node{
bool exist;
int drops,time;
}map[111][111];
struct water{
int dir;
int wx,wy;
};
queue<water> q1;
queue<water> q2;
void broken(int x,int y){
map[x][y].exist=false;
water w;w.wx=x;w.wy=y;
w.dir=1;q1.push(w);
w.dir=2;q1.push(w);
w.dir=3;q1.push(w);
w.dir=4;q1.push(w);
}
bool panduan(water w,int k){
if(map[w.wx][w.wy].exist==true){
map[w.wx][w.wy].drops++;
map[w.wx][w.wy].time=k;
return true;
}
return false;
}
int x[111],y[111],val[111];
int r,c,n,t;
int main(int argc, char *argv[])
{
while(scanf("%d%d%d%d",&r,&c,&n,&t)!=EOF){
int i,j;
for(i=0;i<111;i++){
for(j=0;j<111;j++) {
map[i][j].drops=map[i][j].time=0;
map[i][j].exist=false;
}
}
for(i=0;i<n;i++){
scanf("%d%d%d",&x[i],&y[i],&val[i]);
map[x[i]][y[i]].exist=true;
map[x[i]][y[i]].drops=val[i];
}
int sx,sy;
scanf("%d%d",&sx,&sy);
int k;
broken(sx,sy);
for(k=1;k<=t;k++){
while(!q1.empty()){
water w=q1.front();
q1.pop();
if(w.dir==1){
if(w.wx>1) {w.wx--;q2.push(w);}
}
if(w.dir==2){
if(w.wx<r) {w.wx++;q2.push(w);}
}
if(w.dir==3){
if(w.wy>1) {w.wy--;q2.push(w);}
}
if(w.dir==4){
if(w.wy<c) {w.wy++;q2.push(w);}
}
}
while(!q2.empty()){
water w=q2.front();
q2.pop();
if(panduan(w,k)==false) q1.push(w);
}
for(i=0;i<n;i++){
if(map[x[i]][y[i]].exist==true&&map[x[i]][y[i]].drops>=5) broken(x[i],y[i]);
}
}
while(!q1.empty()) q1.pop();
while(!q2.empty()) q2.pop();
for(i=0;i<n;i++){
if(map[x[i]][y[i]].exist==false) printf("0 %d\n",map[x[i]][y[i]].time);
else printf("1 %d\n",map[x[i]][y[i]].drops);
}
}
return 0;
}



猜你喜欢

转载自blog.csdn.net/nature_ran/article/details/79125324
xyz