HDU5336-XYZ and Drops-模拟

模拟水珠那个游戏。

小水珠超过边界会消失。

会有两个水珠同时到达一个size=4大水珠的情况。要移动完统一爆炸

  1 #include <vector>
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <algorithm>
  5
  6 //using namespace std;
  7
  8 const int maxn = 100+10;
  9 int r,c,n,T;
 10
 11 int dx[] = {0,0,1,-1};
 12 int dy[] = {1,-1,0,0};
 13
 14 struct dp
 15 {
 16     int x,y;
 17     int dir;
 18     bool die;
 19     dp(int _x,int _y,int _dir):x(_x),y(_y),dir(_dir){
 20         die = false;
 21     }
 22     bool out()
 23     {
 24         return (x < 1 || x > r || y < 1 || y > c);
 25     }
 26     void kill()
 27     {
 28         die = true;
 29     }
 30     void move()
 31     {
 32         x += dx[dir];
 33         y += dy[dir];
 34         if(out())
 35         {
 36             kill();
 37             return ;
 38         }
 39     }
 40     bool alive()
 41     {
 42         return !die;
 43     }
 44 };
 45 std::vector <dp> drops;
 46
 47 struct wdp
 48 {
 49     int x,y;
 50     int siz;
 51     int t;
 52     int id;
 53     void display()
 54     {
 55         printf("%d %d\n",siz==-1? 0:1,siz==-1?t:siz);
 56     }
 57     void add(int tim)
 58     {
 59         if(siz == -1) return ;
 60         siz += 1;
 61     }
 62     void split(int tim)
 63     {
 64         if(siz > 4)
 65         {
 66             siz = -1;
 67             t = tim;
 68             //printf("time:%d %d crack\n",tim,id);
 69             for(int i=0;i<4;i++)
 70             {
 71                 drops.push_back(dp(x,y,i));
 72             }
 73         }
 74     }
 75     bool alive()
 76     {
 77         return siz != -1;
 78     }
 79 }waterdrop[maxn];
 80
 81 bool merge(dp &a,wdp &b)
 82 {
 83     return (a.x == b.x && a.y == b.y);
 84 }
 85
 86 void roll(int tim)
 87 {
 88     int cnt = drops.size();
 89     for(int i=0;i<cnt;i++) if(drops[i].alive())
 90     {
 91         drops[i].move();
 92         if(!drops[i].alive()) continue;
 93         //printf("drops: [%d,%d]\n",drops[i].x,drops[i].y);
 94         for(int j=0;j<n;j++) if(waterdrop[j].alive())
 95         {
 96             if(merge(drops[i],waterdrop[j]))
 97             {
 98                 waterdrop[j].add(tim);
 99                 drops[i].kill();
100                 break ;
101             }
102         }
103     }
104     for(int i=0;i<n;i++) waterdrop[i].split(tim);
105 }
106
107 int main()
108 {
109     //freopen("input.txt","r",stdin);
110     while(~scanf("%d%d%d%d",&r,&c,&n,&T))
111     {
112         int x,y,siz;
113         drops.clear();
114         for(int i=0;i<n;i++)
115         {
116             scanf("%d%d%d",&x,&y,&siz);
117             waterdrop[i].x = x;
118             waterdrop[i].y = y;
119             waterdrop[i].siz = siz;
120             waterdrop[i].id = i+1;
121         }
122         scanf("%d%d",&x,&y);
123         for(int i=0;i<4;i++)
124         {
125             drops.push_back(dp(x,y,i));
126         }
127         for(int i=1;i<=T;i++)
128         {
129             roll(i);
130         }
131         for(int i=0;i<n;i++)
132         {
133             waterdrop[i].display();
134         }
135     }
136 }

想到了大一刚开始做的那个傻x坦克大战- -当时写一个判断子弹写半天

时间: 2024-10-16 21:40:39

HDU5336-XYZ and Drops-模拟的相关文章

hdu5336 XYZ and Drops (模拟+vector删除第i个元素)

题目链接: hdu5336 XYZ and Drops 模拟题一道,比较水,但是因为题意曲折 顺带vector的删除操作也是不太明白 总之逗了很长时间 删除第i个元素 v.erase(v.begin() + i); 删完后后面的元素都会往前移一个,所以下一个元素还是v[i] 也可以下面这样 it = v.erase(it); //erase()返回值是指向下一个元素的指针 //#define __LOCAL //#define __LLD #include <stdio.h> #include

解题报告 之 HDU5336 XYZ and Drops

解题报告 之 HDU5336 XYZ and Drops Description XYZ is playing an interesting game called "drops". It is played on a  grid. Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property "size". The waterdrop cracks

Hdu 5336 XYZ and Drops (bfs 模拟)

题目链接: Hdu 5336 XYZ and Drops 题目描述: 有一个n*m的格子矩阵,在一些小格子里面可能会有一些水珠,每个小水珠都有一个size.现在呢,游戏开始咯,在一个指定的空的小格子里面有一个将要向四周爆裂的水珠,在下一面分别向上,下,左,右四个方向发射一个小水滴,(小水滴与水珠同,小水滴没有size),当小水滴走向一个格子,这个格子如果是空或者有其他的小水滴同时走到这个格子的情况下,对小水滴的运动轨迹是不影响的.但是遇到水珠的话,小水滴就会被吸收,水珠每次吸收一个小水滴size

HDU 5336 XYZ and Drops (模拟+搜索,详解)

题目链接: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): 725    Accepted Submission(s): 201 Problem Description XYZ is playing an in

HDU 5336——XYZ and Drops——————【广搜BFS】

XYZ and Drops Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1250    Accepted Submission(s): 407 Problem Description XYZ is playing an interesting game called "drops". It is played on a r∗

XYZ and Drops (hdu 5336 bfs)

XYZ and Drops Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 588    Accepted Submission(s): 157 Problem Description XYZ is playing an interesting game called "drops". It is played on a r?

HDU 5336 XYZ and Drops(模拟十滴水游戏 BFS啊)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=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 &quo

hdu 5336 XYZ and Drops 【BFS模拟】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5336 题意:给你一个r*c的网格,有的网格为空,有的有水,再给出一个爆炸点,从这个点向四周爆出四个水滴,若碰到水则融为一体,若碰到其他水滴直接跑过去互不影响,每秒可跑一格,若水中水滴数量超过4则爆开,问T秒后网格的状态是怎样的. 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <li

HDU 5336(2015多校4)-XYZ and Drops(bfs)

题目地址:HDU 5336 题意:有一个r 行 c 列的格子,给出n个格子里有水滴的大小.再给出时间限制T,使得水滴从(sx,sy)位置开始爆破,当飞渐的水遇到格子里的静态水时就会聚在一起,当聚集的水滴大小>4时就会爆破.问在T时给定的n个位置格子里的水滴情况,如果没有爆破就输出:1 格子里水滴大小.否则输出:0 爆破的时间. #include <stdio.h> #include <math.h> #include <string.h> #include <

多校 hdu

XYZ and Drops Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 430    Accepted Submission(s): 105 Problem Description XYZ is playing an interesting game called "drops". It is played on a r?