HDU5336-XYZ and drops-Simulation

Source: Internet
Author: User

Simulate the game of water droplets.

The beads will disappear beyond the border.

There will be two drops of water at the same time to reach a size=4 flood bead situation. To move through the unified explosion

1#include <vector>2#include <cstdio>3#include <cstring>4#include <algorithm>5 6 //using namespace std;7 8 Const intMAXN = -+Ten;9 intr,c,n,t;Ten  One intDx[] = {0,0,1,-1}; A intDy[] = {1,-1,0,0}; -  - structDP the { -     intx, y; -     intdir; -     BOOLDie ; +dpint_x,int_y,int_dir): X (_x), Y (_y), dir (_dir) { -Die =false; +     } A     BOOL  out() at     { -         return(X <1|| X > R | | Y <1|| Y >c); -     } -     voidKill () -     { -Die =true; in     } -     voidMove () to     { +X + =Dx[dir]; -Y + =Dy[dir]; the         if( out()) *         { $ Kill ();Panax Notoginseng             return ; -         } the     } +     BOOLAlive () A     { the         return!Die ; +     } - }; $Std::vector <dp>drops; $  - structWDP - { the     intx, y; -     intsiz;Wuyi     intT; the     intID; -     voiddisplay () Wu     { -printf"%d%d\n", siz==-1?0:1, siz==-1?t:siz); About     } $     voidAddintTim) -     { -         if(Siz = =-1)return ; -Siz + =1; A     } +     voidSplitintTim) the     { -         if(Siz >4) $         { theSiz =-1; thet =Tim; the             //printf ("time:%d%d crack\n", tim,id); the              for(intI=0;i<4; i++) -             { in Drops.push_back (DP (x,y,i)); the             } the         } About     } the     BOOLAlive () the     { the         returnSiz! =-1; +     } - }WATERDROP[MAXN]; the Bayi BOOLMerge (DP &AMP;A,WDP &b) the { the     return(a.x = = b.x && A.y = =b.y); - } -  the voidRollintTim) the { the     intCNT =drops.size (); the      for(intI=0; i<cnt;i++)if(Drops[i].alive ()) -     { the Drops[i].move (); the         if(!drops[i].alive ())Continue; the         //printf ("Drops: [%d,%d]\n", drops[i].x,drops[i].y);94          for(intj=0; j<n;j++)if(Waterdrop[j].alive ()) the         { the             if(merge (Drops[i],waterdrop[j])) the             {98 Waterdrop[j].add (Tim); About Drops[i].kill (); -                  Break ;101             }102         }103     }104      for(intI=0; i<n;i++) Waterdrop[i].split (Tim); the }106 107 intMain ()108 {109     //freopen ("Input.txt", "R", stdin); the      while(~SCANF ("%d%d%d%d",&r,&c,&n,&T))111     { the         intX,y,siz;113 drops.clear (); the          for(intI=0; i<n;i++) the         { thescanf"%d%d%d",&x,&y,&siz);117waterdrop[i].x =x;118WATERDROP[I].Y =y;119Waterdrop[i].siz =siz; -Waterdrop[i].id = i+1;121         }122scanf"%d%d",&x,&y);123          for(intI=0;i<4; i++)124         { the Drops.push_back (DP (x,y,i));126         }127          for(intI=1; i<=t;i++) -         {129 Roll (i); the         }131          for(intI=0; i<n;i++) the         {133 Waterdrop[i].display ();134         }135     }136}

Think of the first one to do the stupid X-tank war-when writing a judgment bullets written half a day

HDU5336-XYZ and drops-Simulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.