zoukankan      html  css  js  c++  java
  • 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
    ",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
    ",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]
    ",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坦克大战- -当时写一个判断子弹写半天

  • 相关阅读:
    公有云数据库服务的申请与使用
    linux集群
    shell基础知识
    LNMP环境配置
    LAMP环境搭建与配置
    12月17日linux学习
    12月16日linux学习(文档的压缩与打包)
    12月13、14号linux学习
    12月12日linux学习
    目录结构
  • 原文地址:https://www.cnblogs.com/helica/p/5755163.html
Copyright © 2011-2022 走看看