"Bzoj 1033" [ZJOI2008] kill Ant Antbuster

Source: Internet
Author: User

1033: [ZJOI2008] kill ant antbuster time limit: Sec Memory Limit: ten MB
Submit: 583 Solved: 230
[Submit] [Status] Description

Recently, Jia Jia fan on a fun little game: Antbuster. The rules of the game are very simple: on a map, the upper left corner is the ant nest, the lower right corner is the cake, the ants will continue to crawl out of the nest, trying to move the cake back to the ant nest. And your task is to build a defensive tower with the original funds and the bonuses of the ants, and kill the ants who are trying to rob you of the cake.-Attach a game:

In order to get the highest possible score, Allison designed a lot of ways to build a tower, but after trying a small part of it, Allison found that the game is too time-consuming. In order to save time, Allison decided to write a program, for each program, simulation game process, according to the effect to determine the merits of the program. According to some of the experience accumulated in the game, as well as some parameters found on the internet, Allison guessed the ant crawl algorithm, and assume that the game ants are also in accordance with this rule to choose the route: 1, every second beginning, the ants are in the plane on a certain point. 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. OneSome 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 Ant nest again: 1, if the map of ants less than 6, and the hole no ant, then every second in the nest will climb out an ant, until the map of the number of ants 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, the introduction of the cake: 1, for simplicity, you can think that at this time only the last piece of cake. 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 with the cake is dead after the attack, the cakeInstantaneous return to position. 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.

Input

The first line of input is 2 integers separated by a space, N, M, respectively, indicating the length and width of the map. The second line is 3 integers separated by spaces, S, D, R, which in turn indicate the number of turrets, single attack damage, and range of attacks. Next S line, each line is 2 spaces separated by the integer x, y, describes the position of a turret. Of course, there must be no turret in the hole of the ant colony and the place where the cake is located. The last line is a positive integer t, which represents the first T-second of the game we simulated.

Output

If the ant grabs the cake in the second or before the first time, output a line of "game over after X seconds", where X is the end of the game, otherwise output "the game is going on". If the game ends in t seconds or before, output all the ant's information at the end of the game, otherwise output T-seconds after all the ant's information. The format is as follows: The first line is 1 integers s, which represents the total number of ants alive at this time. Next s line, 5 integers per line, followed by an ant's age (in seconds), rank, current amount of blood, and position on the map (a, B). The output is sorted by the age of the ants.

Sample Input8 8
2 10 1
7 8
8 6
5Sample OutputThe game is going on
5
5 1 4) 1 4
4 1 4) 0 4
3 1 4) 0 3
2 1 4) 0 2
1 1 4) 0 1HINT

Sample Description:

The map of 3*5, with 1 single damage of 1, and a laser turret with an attack range of 2, is located (2,2), simulating the first 5 seconds of the game. In 5 seconds, 5 ants were born, crawling eastward, of which the 1th to 4th was wounded by the Laser tower at the point of passing (0,2) 1 blood. In the first 5 seconds, the earliest born ant in accordance with the rules of movement to move eastward, but because of the role of rule 4, it found in the north and westward movement will reach the unreachable point, eventually chose to move south.


Data Description:

100% of data Meet 1≤n,m≤8,s≤20,t≤200,000


Very troublesome Simulations (code questions)


This problem basically is to follow the test instructions all the situation to deal with it.


A little bit to think about is the ant with the cake, the ants on the line will be hit.


This is the relationship between the line and the circle, directly to find the center of the distance from the straight line, and the radius of the circle can be compared. (ask for a distance with a fork product divided by length)


#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < cstdlib> #include <cmath> #define EPS 1e-9#define LL long longusing namespace Std;int n,m,s,d,r,l,r,t,cake,fx[5] [3],v[10][10],me[10][10];struct pre{int level; LL Blood;} A[200005];struct point{int x, y;} P[25];struct Ant{int X,y,px,py,old,carry,level; LL Blood;} Q[250000];void Birth () {if (r-l+1<6&&!v[0][0]) {Ant x;r++;x.old=x.x=x.px=x.py=x.y=x.carry=0;x.blood=a[r] . blood,x.level=a[r].level;q[r]=x;v[0][0]=r;}} BOOL Judge () {for (int i=l;i<=r;i++) if (q[i].carry&&q[i].x==0&&q[i].y==0) return True;return false;} BOOL Can (Ant a,int x,int y) {if (x<0| | y<0| | x>n| | y>m| | v[x][y]| | (a.px==x&&a.py==y)) return False;return true;}    void Move () {for (int i=l;i<=r;i++) {int des=-1;    int ma=-1;    int k=0;    if (Q[i].carry) k=3;    me[q[i].x][q[i].y]+= (2+K); for (int j=0;j<4;j++) {int x=q[i].x+fx[j][1],y=q[i].y+fx[j][2]; if (!caN (q[i],x,y)) continue;    Ma=max (Ma,me[x][y]); } for (int j=0;j<4;j++) {int x=q[i].x+fx[j][1],y=q[i].y+fx[j][2];if (!can (q[i],x,y)) continue;if (Ma==me[x][y]) {D    Es=j;break;}                                         } if (Des==-1) {q[i].px=q[i].x,q[i].py=q[i].y;if (cake&&q[i].x==n&&q[i].y==m) {cake=0;q[i].carry=1;        LL B=a[6*q[i].level].blood; Q[i].blood=min (b,q[i].blood+ (LL) B/2);}    Continue        } if ((q[i].old+1)%5==0) {while (1) {des= (des-1+4)%4;    int X=q[i].x+fx[des][1],y=q[i].y+fx[des][2];if (CAN (q[i],x,y)) break;}            } int x=q[i].x+fx[des][1],y=q[i].y+fx[des][2];    v[q[i].x][q[i].y]=0;            V[x][y]=i; if (x==n&&y==m&&cake) {cake=0,q[i].carry=1;    ll B=a[6*q[i].level].blood;q[i].blood=min (b,q[i].blood+ (LL) B/2); } q[i].px=q[i].x,q[i].py=q[i].y,q[i].x=x,q[i].y=y;} }int dis2 (int ax,int ay,int x,int y) {return (ax-x) * (ax-x) + (ay-y) * (ay-y);} int Cross (point p,ant tar,ant mid) {if (Dis2 (p.x,p.y,miD.X,MID.Y) >r*r) return 0;int abx=tar.x-p.x,aby=tar.y-p.y,acx=mid.x-p.x,acy=mid.y-p.y;int dot,len,dis;dot=abx* Acx+aby*acy,len=dis2 (P.X,P.Y,TAR.X,TAR.Y); if (dot<0) return 0;else if (Dot>len) return 0;else{dis= (p.x-mid.x) * ( TAR.Y-MID.Y)-(tar.x-mid.x) * (P.Y-MID.Y); return dis*dis*4<=len;}} void Deal_death () {int Now=r;while (now>=l) {if (q[now].blood<0) {if (Q[now].carry) Q[now].carry=0,cake=1;v[q[now ].x][q[now].y]=0;for (int i=now-1;i>=l;i--) q[i+1]=q[i];l++;} else now--;}} void Attack () {if (cake) {for (int i=1;i<=s;i++) {int mi2= (r+1) * (r+1), for (int j=l;j<=r;j++) mi2=min (Mi2,dis2 (p[i). X,P[I].Y,Q[J].X,Q[J].Y)), if (mi2<= (r*r)) {int x=0;for (int j=l;j<=r;j++) if (Dis2 (P[I].X,P[I].Y,Q[J].X,Q[J].Y) = =MI2) {x=j;break;} Q[x].blood-=d;}}} Else{int x;for (int i=l;i<=r;i++) if (q[i].carry) {x=i;break;} for (int i=1;i<=s;i++) {if (Dis2 (P[I].X,P[I].Y,Q[X].X,Q[X].Y) <=r*r) {q[x].blood-=d;for (int j=l;j<=r;j++) if (              J!=X) q[j].blood-= (Cross (P[i],q[x],q[j]) *d); continue;}          int mi2= (r+1) * (r+1); for (int j=l;j<=r;j++) if (j!=x) mi2=min (Mi2,dis2 (P[I].X,P[I].Y,Q[J].X,Q[J].Y)); if (mi2< = (r*r)) {int x=0;for (int j=l;j<=r;j++) if (J!=i&&dis2 (P[I].X,P[I].Y,Q[J].X,Q[J].Y) ==mi2) {x=j;break;} Q[x].blood-=d;}}} Deal_death ();} void Finish () {for (Int. i=0;i<=n;i++) for (int j=0;j<=m;j++) Me[i][j]=max (me[i][j]-1,0), for (int i=l;i<=r;i++) Q [i].old++;} void Solve () {int over=0;cake=1;for (int i=1;i<=t;i++) {Birth (); Move (); Attack (); if (Judge ()) {over=i;break;} Finish ();} if (over) printf ("game-over-%d seconds\n", over), elseprintf ("The game was going on\n");p rintf ("%d\n", r-l+1); for (int i =l;i<=r;i++) {Ant x=q[i];p rintf ("%d%d%lld%d%d\n", x.old,x.level,x.blood,x.x,x.y);}} Double Pow (double a,int n) {double base=a,ans=1.0;while (n) {if (n&1) ans*=base;base*=base;n>>=1;} return ans;} void Prepare () {for (int i=0;i<=400;i++) {ll blood= (LL) (4*pow (1.1,i+1)), for (int j=i*6+1;j<=i*6+6;j++) a[j].level =i+1,a[j].blood=blood;} memset (Me,0,sizeof (Me));Fx[0][1]=fx[2][1]=0,fx[0][2]=1,fx[2][2]=-1;fx[1][2]=fx[3][2]=0,fx[1][1]=1,fx[3][1]=-1;}        int main () {l=1; scanf ("%d%d", &n,&m), scanf ("%d%d%d", &s,&d,&r), for (int i=1;i<=s;i++) scanf ("%d%d", &p[i] . X,&p[i].y), v[p[i].x][p[i].y]=250000;scanf ("%d", &t); Prepare (); Solve (); return 0;}



Sentiment:

WA has not been several times:

1. If ants can't move, they need to know if they can get the cake.


2. Forget to add blood to the ant who gets the cake.

"Bzoj 1033" [ZJOI2008] kill Ant Antbuster

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.