zoukankan      html  css  js  c++  java
  • 2015 Multi-University Training Contest 4 hdu 5336 XYZ and Drops

    XYZ and Drops

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 505    Accepted Submission(s): 122


    Problem Description
    XYZ is playing an interesting game called "drops". It is played on a rc 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 (xy), before the first second there is a waterdrop cracking at position (xy). XYZ wants to know each waterdrop's status after Tseconds, can you help him?

    1r1001c1001n1001T10000
     
    Input
    The first line contains four integers rcn and Tn stands for the numbers of waterdrops at the beginning. 
    Each line of the following n lines contains three integers xiyisizei, meaning that the i-th waterdrop is at position (xiyi) and its size is sizei. (1sizei4)
    The next line contains two integers xy

    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 AiBi
    If the i-th waterdrop cracks in T seconds, Ai=0Bi= the time when it cracked. 
    If the i-th waterdrop doesn't crack in T seconds, Ai=1Bi= 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
     
    解题:直接模拟爆炸情况。。。
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 520;
     4 const int dir[4][2] = {-1,0,0,-1,1,0,0,1};
     5 int mp[maxn][maxn],r,c,n,T,x,y;
     6 struct waterdrop {
     7     int x,y,sz,btime;
     8     bool crack;
     9     waterdrop(int a = 0,int b = 0,int c = 0,int d = 0) {
    10         x = a;
    11         y = b;
    12         sz = c;
    13         btime = d;
    14     }
    15 } wp[maxn];
    16 struct drop {
    17     int x,y,time,o;
    18     drop(int a = 0,int b = 0,int c = 0,int d = 0) {
    19         x = a;
    20         y = b;
    21         time = c;
    22         o = d;
    23     }
    24 };
    25 queue<drop>q;
    26 bool isIn(int x,int y) {
    27     return x > 0 && x <= r && y > 0 && y <= c;
    28 }
    29 void bfs() {
    30     for(int i = 0; i < 4; ++i)
    31         q.push(drop(x,y,0,i));
    32     while(!q.empty()) {
    33         drop cur = q.front();
    34         q.pop();
    35         if(cur.time >= T) return;
    36         int nx = cur.x + dir[cur.o][0];
    37         int ny = cur.y + dir[cur.o][1];
    38         if(!isIn(nx,ny)) continue;
    39         int idx = mp[nx][ny];
    40         if(idx == -1 || wp[idx].crack && wp[idx].btime != cur.time+1) q.push(drop(nx,ny,cur.time+1,cur.o));
    41         else if(!wp[idx].crack) {
    42             wp[idx].sz++;
    43             if(wp[idx].sz > 4) {
    44                 wp[idx].crack = true;
    45                 wp[idx].btime = cur.time+1;
    46                 for(int k = 0; k < 4; ++k)
    47                     q.push(drop(wp[idx].x,wp[idx].y,cur.time+1,k));
    48             }
    49         }
    50     }
    51 }
    52 int main() {
    53     while(~scanf("%d%d%d%d",&r,&c,&n,&T)) {
    54         memset(mp,-1,sizeof mp);
    55         while(!q.empty()) q.pop();
    56         for(int i = 0; i < n; ++i) {
    57             scanf("%d%d%d",&wp[i].x,&wp[i].y,&wp[i].sz);
    58             wp[i].crack = false;
    59             mp[wp[i].x][wp[i].y] = i;
    60             if(wp[i].sz > 4) {
    61                 wp[i].crack = true;
    62                 wp[i].btime = 0;
    63                 for(int k = 0; k < 4; ++k)
    64                     q.push(drop(wp[i].x,wp[i].y,0,k));
    65             }
    66         }
    67         scanf("%d%d",&x,&y);
    68         bfs();
    69         for(int i = 0; i < n; ++i)
    70             printf("%d %d
    ",!wp[i].crack,wp[i].crack?wp[i].btime:wp[i].sz);
    71     }
    72     return 0;
    73 }
    View Code
  • 相关阅读:
    让WPF的Popup不总置顶的解决方案
    virtio 驱动的数据结构理解
    关于Linux下面msyql安装后并未设置初始密码,但是登录报错“Access denied for user 'root'@'localhost' (using password: NO)”的解决方案
    gulp初涉
    前后端分离--构建前端Mock Server--windows部署rap
    一些css小用法总结(持续更新~)
    js原生封装自定义滚动条
    ie下面兼容性问题的一些总结
    关于html水平垂直居中的一些总结吧
    C# 正则表达式匹配string字符串中的时间串(yyyyMMdd)
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4690978.html
Copyright © 2011-2022 走看看