显示代码纯文本
#pragma GCC optimize ("O3")
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int dis_pp(int x,int y,int x0,int y0){return (x-x0)*(x-x0)+(y-y0)*(y-y0);}
int ant_num,pre[205000],nxt[205000],first,last,ant_tot;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
struct ANT{
int level,old,blood,up;
int x,y,lx,ly;
int cake;
}ant[205000];
int can_num,can_d,can_r,tar;
struct CANNON{
int x,y,d,r,target;
}can[25];
int n,m,T;
int fm[10][10];
int th[10][10];
void del(int x){
th[ant[x].x][ant[x].y]=0;
if(first==x)first=nxt[x];
if(last==x)last=pre[x];
pre[nxt[x]]=pre[x];
nxt[pre[x]]=nxt[x];
if(ant[x].cake)tar=0;
ant_num--;
}
void birth(){
if(ant_num<6&&!th[0][0]){
ant_num++;ant_tot++;
if(last==0)first=ant_tot;
nxt[last]=ant_tot;pre[ant_tot]=last;
last=ant_tot;
nxt[last]=0; pre[0]=last;
ant[last].level=(ant_tot-1)/6+1;
ant[last].up=ant[last].blood=(int)(4*(double)pow(1.1,ant[last].level));
ant[last].old=1; ant[last].cake=0;
ant[last].x=ant[last].y=ant[last].lx=ant[last].ly=0;
th[0][0]=1;
}
}
void left(){
for(int i=first;i;i=nxt[i]){
if(ant[i].cake)fm[ant[i].x][ant[i].y]+=5;
else fm[ant[i].x][ant[i].y]+=2;
}
}
bool pos_check(int x,int y,int z){
return x>=0&&x<=n&&y>=0&&y<=m&&!th[x][y]&&(ant[z].lx!=x||ant[z].ly!=y);
}
void move(){
for(int i=first,x,y;i;i=nxt[i]){
int f[4]={0},bo[4]={0},pos=-1,maxn=-1;
x=ant[i].x;y=ant[i].y;
for(int j=0;j<4;j++)if(pos_check(x+dx[j],y+dy[j],i)){
bo[j]=1;
f[j]=fm[x+dx[j]][y+dy[j]];
if(f[j]>maxn){maxn=f[j];pos=j;}
}
if(pos==-1){
if(ant[i].x==n&&ant[i].y==m&&!tar){
ant[i].cake=1; tar=i;
ant[i].blood+=(int)ant[i].up/2.0;
ant[i].blood=min(ant[i].blood,ant[i].up);
}
ant[i].lx=ant[i].x;
ant[i].ly=ant[i].y;
continue;
}
if(ant[i].old%5==0){
pos--;if(pos==-1)pos=3;
while(!bo[pos]){pos--;if(pos==-1)pos=3;}
}
th[x][y]=0;
ant[i].lx=x;ant[i].ly=y;
ant[i].x=x+dx[pos]; ant[i].y=y+dy[pos];
th[ant[i].x][ant[i].y]=1;
if(ant[i].x==n&&ant[i].y==m&&!tar){
ant[i].cake=1; tar=i;
ant[i].blood+=(int)ant[i].up/2.0;
ant[i].blood=min(ant[i].blood,ant[i].up);
}
}
}
void fight(){
for(int i=1;i<=can_num;i++){
can[i].target=0;
int dis[7];int now=0,minn=0x7ffff,final,A,B,C;
if(tar&&dis_pp(can[i].x,can[i].y,ant[tar].x,ant[tar].y)<=can_r*can_r)can[i].target=tar;
else for(int j=first;j;j=nxt[j]){
dis[++now]=dis_pp(can[i].x,can[i].y,ant[j].x,ant[j].y);
if(dis[now]<=can_r*can_r){
if(dis[now]<minn||(dis[now]==minn&&ant[j].old>ant[can[i].target].old)){
can[i].target=j;
minn=dis[now];
}
}
}
final=can[i].target;
if(!final)continue;
A=ant[final].y-can[i].y;
B=can[i].x-ant[final].x;
C=ant[final].x*can[i].y-can[i].x*ant[final].y;
for(int j=first;j;j=nxt[j]){
if(4*(A*ant[j].x+B*ant[j].y+C)*(A*ant[j].x+B*ant[j].y+C)<=(A*A+B*B)){
if((ant[j].x>=can[i].x&&ant[j].x<=ant[final].x)||(ant[j].x<=can[i].x&&ant[j].x>=ant[final].x))
if((ant[j].y>=can[i].y&&ant[j].y<=ant[final].y)||(ant[j].y<=can[i].y&&ant[j].y>=ant[final].y))
ant[j].blood-=can_d;
}
}
}
}
bool check(){
for(int i=first;i;i=nxt[i])
if(ant[i].cake&&ant[i].x==0&&ant[i].y==0)return 1;
return 0;
}
void print(){
printf("%d\n",ant_num);
for(int i=first;i;i=nxt[i])
printf("%d %d %d %d %d\n",ant[i].old-1,ant[i].level,ant[i].blood,ant[i].x,ant[i].y);
}
void end(){
for(int i=first;i;i=nxt[i])if(ant[i].blood<0)del(i);
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)
if(fm[i][j])fm[i][j]--;
}
int gy(){
freopen("antbuster_ex.in","r",stdin);
freopen("antbuster_ex.out","w",stdout);
scanf("%d%d",&n,&m);
scanf("%d%d%d",&can_num,&can_d,&can_r);
for(int i=1;i<=can_num;i++){
scanf("%d%d",&can[i].x,&can[i].y);
th[can[i].x][can[i].y]=1;
can[i].d=can_d;can[i].r=can_r;
}
scanf("%d",&T);
for(int t=1;t<=T;t++){
birth();
left();
move();
fight();
end();
if(check()){
printf("Game over after %d seconds\n",t);
print();
return 0;
}
for(int i=first;i;i=nxt[i])ant[i].old++;
}
printf("The game is going on\n");
print();
return 0;
}
int ryf_love=gy();
int main(){;}
/*
3 5
1 1 2
2 2
5
*/