c语言十滴水游戏代码思路,HDU 5336多校 十滴水模拟

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

第一种方法是枚举的时间,效率较低,比赛时跑了265ms。

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define ll long long

using namespace std;

int jl[1110];

int r,c,n,t;

struct node

{

int x,y,d;

};

int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};

int Map[110][110];

struct node2

{

int water,time;

};

node2 ans [110][110];

int in(int x,int y)

{

if(x>=1&&x<=r&&y>=1&&y<=c)

return 1;

return 0;

}

queue q;

queue q2;

int bfs( )

{

node next,tmp,fen;

int xx,yy;

for(int ttt = 0; ttt<=t; ttt++)

{

// for(int i=1; i<=r; i++)

// {

// for(int j=1; j<=c; j++)

// {

// cout<

// }

// cout<

// }

// cout<

for(int i=0; i

{

xx = jl[i]/1000, yy = jl[i]%1000;

if(Map[xx][yy]>4)

{

Map[xx][yy] = 0;

ans[xx][yy].water = 0;

ans[xx][yy].time = ttt;

for(int j=0; j<4; j++)

{

fen.x = xx,fen.y = yy,fen.d = j;

q.push(fen);

}

}

else

{

ans[xx][yy].water = Map[xx][yy];

}

}

while(!q.empty())

{

node tmp = q.front();

q.pop();

int xx = tmp.x + dir[tmp.d][0];

int yy = tmp.y + dir[tmp.d][1];

if(!in(xx,yy))

continue;

if(Map[xx][yy]==0)

{

next.x = xx;

next.y = yy;

next.d = tmp.d;

q2.push(next);

}

else

Map[xx][yy] ++;

}

while(!q2.empty())

{

q.push(q2.front());

q2.pop();

}

}

return 0;

}

int main()

{

while(cin>>r>>c>>n>>t)

{

memset(Map,0,sizeof(Map));

for(int i=0; i

{

int x,y,z;

scanf("%d%d%d",&x,&y,&z);

jl[i] = x*1000+y;

ans[x][y].water = z;

ans[x][y].time = 0;

Map[x][y] += z;

}

int sx,sy;

cin>>sx>>sy;

while(!q.empty())

q.pop();

while(!q2.empty())

q.pop();

node tmp;

for(int i=0; i<4; i++)

{

tmp.x = sx,tmp.y = sy;

tmp.d = i;

q.push(tmp);

}

bfs();

int ex,ey;

node2 flag ;

for(int i=0; i

{

ex = jl[i]/1000;

ey = jl[i]%1000;

flag = ans[ex][ey];

if(flag.water == 0)

cout<<0<

else

cout<<1<

}

}

return 0;

}

第二种方法只需把当前这一秒所有的小水珠都处理完再判断是否爆裂。赛后跑了46ms。

据说是赛前该小了数据,要不然第一种方法就会T掉。

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define ll long long

using namespace std;

int jl[1110];

int r,c,n,t;

struct node

{

int x,y,d;

int mov;

};

int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};

int Map[110][110];

struct node2

{

int water,time;

};

node2 ans [110][110];

int in(int x,int y)

{

if(x>=1&&x<=r&&y>=1&&y<=c)

return 1;

return 0;

}

queue q;

int bfs( )

{

node next,tmp,fen;

int xx,yy;

while(!q.empty()&&q.front().mov

{

node tmp = q.front();

q.pop();

int xx = tmp.x + dir[tmp.d][0];

int yy = tmp.y + dir[tmp.d][1];

// if(in(xx,yy)) continue;

//如果后面还有判断条件 ,不要这样写

if(in(xx,yy))

{

if(Map[xx][yy]==0)

{

next.x = xx;

next.y = yy;

next.d = tmp.d;

next.mov = tmp.mov + 1;

q.push(next);

}

else

Map[xx][yy] ++;

}

if(q.empty()||q.front().mov != tmp.mov)

{

for(int i=0; i

{

xx = jl[i]/1000, yy = jl[i]%1000;

if(Map[xx][yy]>4)

{

Map[xx][yy] = 0;

ans[xx][yy].water = 0;

ans[xx][yy].time = tmp.mov + 1;

for(int j=0; j<4; ++j)

{

fen.x = xx,fen.y = yy,fen.d = j;

fen.mov = tmp.mov + 1;

q.push(fen);

}

}

else

ans[xx][yy].water = Map[xx][yy];

}

}

}

return 0;

}

int main()

{

while(scanf("%d%d%d%d",&r,&c,&n,&t)!=EOF)

{

memset(Map,0,sizeof(Map));

for(int i=0; i

{

int x,y,z;

scanf("%d%d%d",&x,&y,&z);

jl[i] = x*1000+y;

ans[x][y].water = z;

ans[x][y].time = 0;

Map[x][y] += z;

}

int sx,sy;

scanf("%d%d",&sx,&sy);

while(!q.empty())

q.pop();

node tmp;

for(int i=0; i<4; ++i)

{

tmp.x = sx,tmp.y = sy;

tmp.d = i;

tmp.mov = 0;

q.push(tmp);

}

bfs();

int ex,ey;

node2 flag ;

for(int i=0; i

{

ex = jl[i]/1000;

ey = jl[i]%1000;

flag = ans[ex][ey];

if(flag.water == 0)

printf("0 %d\n",flag.time);

else

printf("1 %d\n",flag.water);

}

}

return 0;

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文:http://blog.csdn.net/u013588639/article/details/47167943

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
4S店客户管理小程序-毕业设计,基于微信小程序+SSM+MySql开发,源码+数据库+论文答辩+毕业论文+视频演示 社会的发展和科学技术的进步,互联网技术越来越受欢迎。手机也逐渐受到广大人民群众的喜爱,也逐渐进入了每个用户的使用。手机具有便利性,速度快,效率高,成本低等优点。 因此,构建符合自己要求的操作系统是非常有意义的。 本文从管理员、用户的功能要求出发,4S店客户管理系统的功能模块主要是实现管理员服务端;首页、个人心、用户管理、门店管理、车展管理、汽车品牌管理、新闻头条管理、预约试驾管理、我的收藏管理、系统管理,用户客户端:首页、车展、新闻头条、我的。门店客户端:首页、车展、新闻头条、我的经过认真细致的研究,精心准备和规划,最后测试成功,系统可以正常使用。分析功能调整与4S店客户管理系统实现的实际需求相结合,讨论了微信开发者技术与后台结合java语言和MySQL数据库开发4S店客户管理系统的使用。 关键字:4S店客户管理系统小程序 微信开发者 Java技术 MySQL数据库 软件的功能: 1、开发实现4S店客户管理系统的整个系统程序; 2、管理员服务端;首页、个人心、用户管理、门店管理、车展管理、汽车品牌管理、新闻头条管理、预约试驾管理、我的收藏管理、系统管理等。 3、用户客户端:首页、车展、新闻头条、我的 4、门店客户端:首页、车展、新闻头条、我的等相应操作; 5、基础数据管理:实现系统基本信息的添加、修改及删除等操作,并且根据需求进行交流信息的查看及回复相应操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值