XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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
Author
XJZX
Source
/*******************************************************************************/
此题的原型应是“十滴水”这个游戏,
http://www.3366.com/game/1000154.shtml
原先的想法是利用优先队列,按照时间的先后将水滴依次放进队列
但是一直WA,原因在于
①同一时间到达同一个水滴的问题;
INPUT
4 4 5 100
1 1 4
1 2 3
1 3 4
1 4 4
2 3 4
2 4
OUTPUT
1 4
1 4
0 2
0 1
0 1
②需要多个不同时间到达才能炸开的处理问题。
例子:
INPUT
5 5 4 100
1 1 3
1 2 4
1 4 4
1 5 3
1 3
OUTPUT
0 4
0 1
0 1
0 4
在此需要提及的一点是多校的Contest Clarifications里admin说c是x轴的方向范围,r是y轴的方向范围,但是多校的数据里全是c==r的情况
可能多校结束之后又添了数据,但是r,c搞错了,变成了r是x轴的范围,c是y轴的范围
以下是原先的错误代码:
/*注意:同时到达同一个水滴的情况*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
struct node
{
int time,id;
bool operator < (const node &a) const
{
return time>a.time;//最小值优先
}
};
int x[105],y[105],z[105],zz[105],v[105][105],s[105][105];
bool vv[105];
int main()
{
int i,j,r,c,n,t,a,b,k,ans;
node w;
while(~scanf("%d%d%d%d",&r,&c,&n,&t))
{
priority_queue<node> q;
memset(v,0,sizeof(v));
memset(s,0,sizeof(s));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
memset(z,0,sizeof(z));
memset(zz,0,sizeof(zz));
memset(vv,false,sizeof(vv));
vector<int> p[105][5];
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&x[i],&y[i],&z[i]);
v[x[i]][y[i]]=i;
}
for(i=1;i<=n;i++)
{
for(j=x[i]+1;j<=r;j++)
if(v[j][y[i]])
p[i][1].push_back(v[j][y[i]]);
for(j=x[i]-1;j>=0;j--)
if(v[j][y[i]])
p[i][2].push_back(v[j][y[i]]);
for(j=y[i]+1;j<=c;j++)
if(v[x[i]][j])
p[i][3].push_back(v[x[i]][j]);
for(j=y[i]-1;j>=0;j--)
if(v[x[i]][j])
p[i][4].push_back(v[x[i]][j]);
}
scanf("%d%d",&a,&b);
if(v[a][b])
{
zz[v[a][b]]=0;
vv[v[a][b]]=true;
v[a][b]=0;
//printf("%d\n",v[a][b]);
}
x[0]=a,y[0]=b;
for(j=a+1;j<=r;j++)
if(v[j][b])
p[0][1].push_back(v[j][b]);
for(j=a-1;j>=0;j--)
if(v[j][b])
p[0][2].push_back(v[j][b]);
for(j=b+1;j<=c;j++)
if(v[a][j])
p[0][3].push_back(v[a][j]);
for(j=b-1;j>=0;j--)
if(v[a][j])
p[0][4].push_back(v[a][j]);
w.id=0;w.time=0;ans=0;
q.push(w);
while(!q.empty())
{
k=q.top().id;
ans=q.top().time;printf("%d %d %d##\n",ans,x[k],y[k]);
for(i=1;i<5;i++)
{
for(j=0;j<p[k][i].size();j++)
{
if(!v[x[p[k][i][j]]][y[p[k][i][j]]]&&ans+abs(x[p[k][i][j]]-x[k])+abs(y[p[k][i][j]]-y[k])==s[x[p[k][i][j]]][y[p[k][i][j]]])
break;
if(v[x[p[k][i][j]]][y[p[k][i][j]]]&&ans+abs(x[p[k][i][j]]-x[k])+abs(y[p[k][i][j]]-y[k])<=t)
{printf("***%d %d %d %d***\n",p[k][i][j],x[p[k][i][j]],y[p[k][i][j]],z[p[k][i][j]]);
z[p[k][i][j]]++;
if(z[p[k][i][j]]>4)
{
w.id=p[k][i][j];
w.time=ans+abs(x[w.id]-x[k])+abs(y[w.id]-y[k]);printf("%d %d %d!!\n",k,w.id,abs(x[w.id]-x[k])+abs(y[w.id]-y[k]));
s[x[w.id]][y[w.id]]=w.time;
q.push(w);
zz[w.id]=w.time;
vv[w.id]=true;
v[x[p[k][i][j]]][y[p[k][i][j]]]=0;
}
break;
}
}//printf("~~\n");
}printf("@@\n");
q.pop();
}
for(i=1;i<=n;i++)
if(vv[i])
printf("0 %d\n",zz[i]);
else
printf("1 %d\n",z[i]);
}
return 0;
}
以下是AC代码:
/*注意:同时到达同一个水滴的情况*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 105;
int a[N][N],b[4][2]={{0,1},{0,-1},{1,0},{-1,0}},r,c,n,t,id[N][N],ans[N][2],temp[N][2];
struct node
{
int time,x,y,b_x,b_y;
node(){}
node(int _time,int _x,int _y,int _b_x,int _b_y):time(_time),x(_x),y(_y),b_x(_b_x),b_y(_b_y){}
};
queue<node> q;
void BFS(int d,int e)
{
int i,j,x,y,time=1,cnt;
node top;
while(!q.empty())
q.pop();
if(a[d][e])
{
a[d][e]=0;
ans[id[d][e]][0]=0;
ans[id[d][e]][1]=0;
}
for(i=0;i<4;i++)
{
x=d+b[i][0];
y=e+b[i][1];
if(x>0&&x<=r&&y>0&&y<=c)
q.push(node(1,x,y,b[i][0],b[i][1]));
}
while(!q.empty()&&time<=t)
{
//cout << "time = " << time << endl;
cnt=0;
while(!q.empty()&&(top=q.front()).time==time)
{
q.pop();
//cout << top.x << " " << top.y << endl;
if(a[top.x][top.y]>0)
{
a[top.x][top.y]++;
temp[cnt][0]=top.x;
temp[cnt++][1]=top.y;
}
else
{
x=top.x+top.b_x;
y=top.y+top.b_y;
if(x>0&&x<=r&&y>0&&y<=c)
q.push(node(top.time+1,x,y,top.b_x,top.b_y));
}
}
//cout << endl;
for(i=0;i<cnt;i++)
if(a[temp[i][0]][temp[i][1]]>4)
{
ans[id[temp[i][0]][temp[i][1]]][0]=0;
ans[id[temp[i][0]][temp[i][1]]][1]=time;
a[temp[i][0]][temp[i][1]]=0;
for(j=0;j<4;j++)
{
x=temp[i][0]+b[j][0];
y=temp[i][1]+b[j][1];
if (x>0&&x<=r&&y>0&&y<=c)
q.push(node(time+1,x,y,b[j][0],b[j][1]));
}
}
time++;
}
for(i=1;i<=r;i++)
for (j=1;j<=c;j++)
if(a[i][j])
{
ans[id[i][j]][0]=1;
ans[id[i][j]][1]=a[i][j];
}
for(i=0;i<n;i++)
printf("%d %d\n",ans[i][0],ans[i][1]);
}
int main()
{
int i,x,y,z,d,e;
while(~scanf("%d%d%d%d",&r,&c,&n,&t))
{
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
{
scanf("%d%d%d",&x,&y,&z);
a[x][y]=z;
id[x][y]=i;
}
scanf("%d%d",&d,&e);
BFS(d,e);
}
return 0;
}

本文介绍了一款名为“Drops”的游戏,该游戏在一个r*c的网格上进行,玩家需要处理水滴的移动、分裂及融合等操作。文章详细分析了游戏的规则,并提供了解决方案的代码实现。

被折叠的 条评论
为什么被折叠?



