Bzoj1033 Kill Ants

Source: Internet
Author: User

Suppose the ant in the game also chooses the route according to this rule:

1, every second beginning, the ants are in the plane on some point on the hour. If the ant does not carry the cake, it will leave 2 units of pheromone at that point, otherwise it will leave 5 units of pheromone. Then the ants will be in the north, south, east, due West Four directions to choose a crawl past.

2, choose the direction of the rule is: first, after climbing a unit length to arrive at that point, can not have other ants or defense tower, and that point can not be ants on the point of a second location (unless the ant was stuck in the last moment, and this moment it still can't move), of course, Ants also do not crawl out of the boundaries of the map (we define these points as unreachable points). If there are multiple choices at this point, the ant will choose the most pheromone to crawl past.

3, if there are still a variety of options, ants first facing east, if East is not an optional direction, it will turn clockwise 90°, again, if not, then turn 90° ... Until you find a way to go.

4, if each ant in the mouth of the hole appears as the 1th second of its activity time, then whenever the ant's activity time in seconds is a multiple of 5, it first in accordance with the rules to determine a direction, in the face of this direction counterclockwise to 90°, if it along the current direction will go to an unreachable point, It will keep turning 90° counterclockwise every time until it faces a point where it can be reached, so the direction that the ants are going to crawl is the final direction.

5, if the ants around are unreachable points, then the ant in this second will choose to stay at the current point. The next second, when determining the direction of the move, is the point at which the last second is at its current stop.

6, you can think of the ant in the selected direction, the moment to move to its target point, for the remainder of the second time, it will stay at the target point.

7, ants are born in the order of movement, was born earlier ants move first.

Then, there is some information about the map:

1. Every second, the pheromone on all points of the map will lose 1 units, if there is pheromone on that point.

2. Some places on the map are forts. The coordinates of the fort are given in the input.

3, the length and width of the map are given in the input, for n * m of the map, its upper-left corner coordinates (0,0), the lower-right corner coordinates (N,M). The location of the Ant Hole is (0,0) and the position of the cake is (n,m).

4, you can think of ants as a diameter of 1 units of the circle, the center of the ant is located on the whole hour.

5. At the beginning of the game, there are no ants on the map, and the content of pheromone on each point is 0.

Some information about the turret: 1, the turret is placed on the map on the whole point.

2, in order to be simple, we think these turrets are laser towers. The laser tower's shooting speed is 1 seconds/times, its attack damage is d/times, the attack range is R. You can think that the tower will start attacking every second after the ants have moved. And, only when the circle center of the ant is not more than R in the straight line of the tower, the tower is counted to get the ant.

3. If an ant is carrying a cake, it will become target, that is, any tower that hits its cannon will be directed at it. If the cake is properly in place, then each tower will be attacked by the ants closest to it, and if there are many ants, it will pick the one that was born earlier.

4, the Laser tower has a strange feature: It has been selected after the target, as long as the target within its range, the tower to the target Ant center line of all ants (here "hit" The decision to indicate that the laser lines and the expression of the ants circle has a common point) will be hit and damage D blood, But the laser does not penetrate its hit target to hit the ants behind it.

5, although in the real game, the tower can be upgraded, but here we think the layout and level of the tower has been set down, no longer change.

Introduce the Ant nest again:

1. If there are less than 6 ants on the map, and there are no ants in the hole, the nest will crawl out an ant every second until the number of ants on the map is 6.

2. The newly born ant stands at the entrance of the cave.

3, each ant has a level, the level determines the amount of the ant's blood, the level of K of the Ant's Blood is an int (4*1.1^k) (int (x) to remove the entire x). Each time the tower is beaten, the blood of the ants is reduced by D. Note that the amount of 0 of the ants can still be energetic to crawl around, only one ant's blood is beaten to a negative, it is only counted dead.

4, the ant level is this calculates: the first 6 born ant is 1 level, 7th to 12th is 2 level, and so on.

Finally, give a description of the cake:

1. For simplicity, you can think that there is only one last piece of cake left at this time. If an ant goes to the cake position and the cake is not carried away, the ant will carry the cake. The ant is returned to the cake after being beaten.

2, if an ant carrying a cake to the ant nest position, we think the ant has successfully robbed the cake, the game is over.

3, the ant carries the cake, the blood quantity will increase int (the ant is born the blood quantity/2), but does not exceed the upper limit.

Organize the events that occurred within 1 seconds: 1 seconds initially, if the number of ants on the map is less than 6, an ant will be born in the hole. The ants then leave some pheromone behind at their own point and consider moving. First-born ants move first. After the move is complete, if an ant is in the cake position and the cake is not taken away, it carries the cake and the amount of blood increases, and at this point it is set to target by all the towers. Then all towers start attacking at the same time. If the ant carrying the cake hangs after the attack, the cake is instantly returned to place. After the attack, if found that the ant carrying the cake is not dead and in the nest position, it is believed that the ant robbed the cake. The game also ends at this point. Finally, the pheromone of all points on the map loses 1 units. The age of all ants is plus 1. This is the end of a long 1 seconds.

#include <cstdio>#include<cmath>intxs[]={1,0,-1,0,0};intys[]={0,1,0,-1,0};intNth=1, n,m,s,d,r,t;intf1[ -][ -],ed[ -][ -],xk[ -],yk[ -];DoubleR;inlineDoubleLenDoubleXDoubleY) {returnsqrt (x*x+y*y);} InlineDoubleLen2 (DoubleXDoubleY) {returnx*x+y*y;} InlineintLen2i (intXintY) {returnx*x+y*y;} InlineBOOLUnintXinty) {    if(Ed[x][y])return 1; returnx<0|| y<0|| x>n| | Y>m;}structant{intX,y,px,py,hp,hp0,cake,lv,age; voidupd ();} as[ -];intp=0;voidAdd () {ant&a= as[p++]; A.x=a.y=a.px=a.py=a.cake=a.age=0; a.lv= (nth+5)/6; Nth++; A.hp0=a.hp=4*pow (1.1, a.lv); ed[0][0]=1;}voidant::upd () {Static intable[4],val[4],mx; MX=-1; F1[x][y]+=cake?5:2;  for(intI=0;i<4; i++){        intx1=x+xs[i],y1=y+Ys[i]; if(UN (x1,y1) | | X1==PX&AMP;&AMP;Y1==PY) able[i]=0; Else{Able[i]=1; Val[i]=F1[x1][y1]; if(F1[X1][Y1]&GT;MX) mx=F1[x1][y1]; }    }    intfx=0;  for(;fx<4; fx++)if(Able[fx]&&mx==val[fx]) Break; if(fx!=4&&age%5==4) {FX= (fx-1&3);  for(intI=0;i<4; I++,fx= (fx-1&3))if(Able[fx]) Break; } px=x;py=y; if(Able[fx]) {Ed[x][y]=0; X+=xs[fx];y+=YS[FX]; Ed[x][y]=1; }}voidAttackintX1,intY1,intX2,inty2) {     for(intI=0; i<p;i++) {ant&a= as[i]; BOOLon=0; if(Len2i (A.x-x2,a.y-y2) >r*R); Else if(Len (X1-A.X,Y1-A.Y) <=0.5001|| Len (X2-A.X,Y2-A.Y) <=0.5001) on=1; Else{            DoubleL=len (x1-x2,y1-y2); DoubleH=fabs ((x1-a.x) * (Y2-A.Y)-(x2-a.x) * (Y1-A.Y))/M; if(h<=0.5001&&fabs (sqrt (len2 (X1-A.X,Y1-A.Y)-h*h) +sqrt (Len2 (X2-A.X,Y2-A.Y)-h*h)-L) <0.0001) on=1; }        if(ON) a.hp-=D; }}intMain () {BOOLCake=1; intT; scanf ("%d%d%d%d%d",&m,&n,&s,&d,&R); R=r+0.0001;  for(intI=1; i<=s;i++) {scanf ("%d%d", yk+i,xk+i); Ed[xk[i]][yk[i]]=1; } scanf ("%d",&t);  for(t=1; t<=t; t++){        if(p<6&&!ed[0][0]) Add ();  for(intI=0; i<p;i++) as[I].upd (); if(Cake) for(intI=0; i<p;i++) {ant&a= as[i]; if(a.x==n&&a.y==L) {Cake=0; A.cake=1; A.HP+=a.hp0/2; if(A.HP&GT;A.HP0) a.hp=a.hp0;  Break; }        }         for(intj=1; j<=s;j++){            inttg=-1, ml=100000;  for(intI=0, l1;i<p;i++){                if((L1=len2i ( as[I].x-xk[j], as[I].y-yk[j]) <=r*R) {                    if( as[I].cake) {tg=i; Break;} if(L1&LT;ML) ml=l1,tg=i; }            }            if(~TG) Attack ( as[Tg].x, as[tg].y,xk[j],yk[j]); }        BOOLGameover=0;  for(intI=0; i<p;i++){            if( as[i].hp<0){                if( as[I].cake] Cake=1; ed[ as[i].x][ as[i].y]=0;  for(intj=i;j<p;j++) as[j]= as[j+1]; --p;--i; }Else if( as[i].cake&& as[i].x==0&& as[i].y==0) gameover=1; }        if(Gameover) {printf ("Game over after%d seconds\n", T); Gotoend; }         for(intI=0; i<p;i++) as[i].age++;  for(intI=0; i<=n;i++){             for(intj=0; j<=m;j++){                if(F1[i][j])--F1[i][j]; }}} puts ("The game is going on"); end:printf ("%d\n", p);  for(intI=0; i<p;i++) {ant&a= as[i]; printf ("%d %d%d%d%d\n", a.age,a.lv,a.hp,a.y,a.x); }    return 0;}

Bzoj1033 Kill Ants

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.