hdu5336&15年多校集训(4)j题(bfs+模拟)
来源:互联网 发布:mac口红rebel试色 编辑:程序博客网 时间:2024/04/29 16:56
题目大意:r*c的方格矩阵中,有n顆大水滴,给出位置和大小(表示为小水珠的数量)。当大水滴的大小超过4时,便会爆裂,变成四颗小水珠,往四个方向运动。小水珠相遇时不会发生碰撞,小水珠和大水滴相遇时相融合。这一秒大水滴爆裂时,四颗小水珠会在同一个格子中,下一秒才会运动。
一开始在位置(A,B)爆裂一颗大水滴。求出T秒是每颗大水滴的状态。
解题思路:这道题不难,但因为题意曲折,而且有些细节问题导致一直wa,基本思路是bfs,利用队列,每次t秒拓展一次结点,然后每次统计下统计队列长度,再搞个变量出来,直到每次出队一个元素,变量-1。
注意点:两个水滴同一时刻,进入同一大水珠,并且大水珠子破裂,容易忽略第二颗水珠,让他在他的方向多一颗水珠。他的方向上应该只能算一颗水珠。
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<queue>using namespace std;const int maxn=110;int r,c,n,T,s_x,s_y;int times[maxn][maxn],s[maxn][maxn];//time用于记录到达时间,s用于记录当前棋盘的状态int x[maxn],y[maxn];struct node{ int x,y,dir; node(int x,int y,int dir):x(x),y(y),dir(dir){}};int dx[]={0,1,0,-1,0};int dy[]={0,0,1,0,-1};int inside(int x,int y){ if(x<1||x>r||y<1||y>c) return 0; else return 1;}void solve(){ queue<node> q; for(int i=1;i<=4;i++) q.push(node(s_x,s_y,i)); for(int t=1;t<=T;t++) { int len=q.size(); if(len==0) return; while(len--) { node v=q.front();q.pop(); int new_x=v.x+dx[v.dir]; int new_y=v.y+dy[v.dir]; if(inside(new_x,new_y)) { if(times[new_x][new_y]==t) continue; if(s[new_x][new_y]) { s[new_x][new_y]++; if(s[new_x][new_y]>4) { s[new_x][new_y]=0; times[new_x][new_y]=t; for(int i=1;i<=4;i++) q.push(node(new_x,new_y,i)); } } else q.push(node(new_x,new_y,v.dir)); } } }}int main(){ while(scanf("%d%d%d%d",&r,&c,&n,&T)!=EOF) { memset(times,0,sizeof(times)); memset(s,0,sizeof(s)); int tmp; for(int i=1;i<=n;i++) { scanf("%d%d%d",&x[i],&y[i],&tmp); s[x[i]][y[i]]=tmp; } scanf("%d%d",&s_x,&s_y); solve(); for(int i=1;i<=n;i++) { if(s[x[i]][y[i]]==0) { printf("0 %d\n",times[x[i]][y[i]]); } else printf("1 %d\n",s[x[i]][y[i]]); } }}
0 0
- hdu5336&15年多校集训(4)j题(bfs+模拟)
- 水滴模拟问题(误)hdu5336
- hdu5325&15年杭电多校集训(3) j题
- hdu5335&15年杭电多校集训(4)i题(bfs+策略)
- J - 非常可乐 (BFS)
- J - Candy Sharing Game(模拟题)
- hdu5336 多校联合第四场1010 模拟+bfs优先队列
- CodeForces 589J -- J. Cleaner Robot (BFS)
- hdu5336 十滴水游戏的模拟
- 【模拟】hdu5336 XYZ and Drops
- UVA11624 Fire! 两次BFS(J)
- J题 游戏模拟
- 模拟赛 J跳(组合数)
- HDU5336 XYZ and Drops 暴力模拟
- hdu 4255(模拟+bfs)
- sdut-2156(模拟,bfs)
- BJ模拟:stwell(BFS)
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J题(BFS)
- C#中 栈和堆上变量的运行速度, 装箱拆箱速度
- 第六章分组函数
- 【HTML】内联框架
- JSON的用法
- 随笔
- hdu5336&15年多校集训(4)j题(bfs+模拟)
- 线性探测法构造哈希表(hash)
- DOM解析器
- Reverse Integer leetcode
- Linux内核——伙伴系统和slab缓存
- uva 1600
- 欢迎使用CSDN-markdown编辑器
- SAX解析器
- socket选项总结(setsocketopt)