显示代码纯文本
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
inline int read(){
int sum(0),f(1);
char ch(getchar());
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';sum=sum*10+(ch^48),ch=getchar());
return sum*f;
}
int n,m,s,d,r,t;
const int mov[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
double xp[40005];
int life[40005];
inline int play_table(){xp[0]=1;for(int i=1;i<=40000;++i)xp[i]=xp[i-1]*1.1,life[i]=(int)(4.0*xp[i]);}
int play(play_table());
bool caketaken,gameover,object[15][15];
int pheromone[15][15];
int newborn,cnt;
inline int get_pointdis(int x,int y,int a,int b){
return (x-a)*(x-a)+(y-b)*(y-b);
}
inline bool checkoutofmap(int x,int y){
return x<0||y<0||x>n||y>m;
}
struct ant{
int posx,posy,lastx,lasty,level,age,HP,blood;
bool takingcake;
ant():posx(0),posy(0),lastx(-1),lasty(-1),age(1),level((newborn-1)/6+1),HP(life[(newborn-1)/6+1]),blood(life[(newborn-1)/6+1]),takingcake(0){}
inline void leave_pheromone(){
if(takingcake)pheromone[posx][posy]+=5;
else pheromone[posx][posy]+=2;
}
inline void set_newpos(int x,int y){
object[posx][posy]=0;
lastx=posx,lasty=posy;
posx=x,posy=y;
object[x][y]=1;
}
inline void move(){
int mx(-1),pos(0),cont(0);
for(int i=0;i<4;++i){
int tmpx(posx+mov[i][0]),tmpy(posy+mov[i][1]);
if(checkoutofmap(tmpx,tmpy)||object[tmpx][tmpy]||(tmpx==lastx&&tmpy==lasty))continue;
++cont;
if(pheromone[tmpx][tmpy]>mx){
mx=pheromone[tmpx][tmpy];
pos=i;
}
}
if(cont==0){
set_newpos(posx,posy);
return;
}
if(cont==1){
set_newpos(posx+mov[pos][0],posy+mov[pos][1]);
return;
}
if(age%5){
for(int i=0;i<4;++i){
int tmpx(posx+mov[i][0]),tmpy(posy+mov[i][1]);
if(checkoutofmap(tmpx,tmpy)||object[tmpx][tmpy]||(tmpx==lastx&&tmpy==lasty))continue;
if(pheromone[tmpx][tmpy]==mx){
set_newpos(tmpx,tmpy);
return;
}
}
}
else{
int lastpos;
for(int i=0;i<4;++i){
int tmpx(posx+mov[i][0]),tmpy(posy+mov[i][1]);
if(checkoutofmap(tmpx,tmpy)||object[tmpx][tmpy]||(tmpx==lastx&&tmpy==lasty))continue;
if(pheromone[tmpx][tmpy]==mx){
lastpos=i;
break;
}
}
for(int i=lastpos-1;i>=0;--i){
int tmpx(posx+mov[i][0]),tmpy(posy+mov[i][1]);
if(checkoutofmap(tmpx,tmpy)||object[tmpx][tmpy]||(tmpx==lastx&&tmpy==lasty))continue;
set_newpos(tmpx,tmpy);
return;
}
for(int i=3;i>=lastpos;--i){
int tmpx(posx+mov[i][0]),tmpy(posy+mov[i][1]);
if(checkoutofmap(tmpx,tmpy)||object[tmpx][tmpy]||(tmpx==lastx&&tmpy==lasty))continue;
set_newpos(tmpx,tmpy);
return;
}
}
}
inline void attack(){
if(posx!=n||posy!=m||caketaken)return;
caketaken=takingcake=1;
HP=min(HP+(blood>>1),blood);
}
}but[10];
struct tower{
int x,y;
tower(int a=0,int b=0):x(a),y(b){}
inline void cal_attack(int num){
if(x==but[num].posx){
int min__y(min(y,but[num].posy)),max__y(max(y,but[num].posy));
for(int i=1;i<=cnt;++i)
if(but[i].posx==x&&but[i].posy<=max__y&&but[i].posy>=min__y)
but[i].HP-=d;
return;
}
int max__x(max(x,but[num].posx)),min__x(min(x,but[num].posx)),max__y(max(y,but[num].posy)),min__y(min(y,but[num].posy));
double a((double)(but[num].posy-y)/(double)(but[num].posx-x)),b(-1),c((double)y-(double)x*a);
double denominator(a*a+b*b);
for(int i=1;i<=cnt;++i)
if(but[i].posx<=max__x&&but[i].posx>=min__x&&but[i].posy>=min__y&&but[i].posy<=max__y){
double numerator(a*(double)but[i].posx+b*(double)but[i].posy+c);
if(numerator*numerator*4.0<=denominator)but[i].HP-=d;
}
}
inline void attack(){
if(caketaken){
for(int i=1;i<=cnt;++i)
if(but[i].takingcake&&get_pointdis(x,y,but[i].posx,but[i].posy)<=r*r){
cal_attack(i);
return;
}
}
int mn(r*r);
for(int i=1;i<=cnt;++i)
mn=min(mn,get_pointdis(x,y,but[i].posx,but[i].posy));
for(int i=1;i<=cnt;++i)
if(get_pointdis(x,y,but[i].posx,but[i].posy)==mn){
cal_attack(i);
return;
}
}
}tow[30];
inline bool cmp_HP(const ant &a,const ant &b){
return a.HP>b.HP;
}
inline bool cmp_age(const ant &a,const ant &b){
return a.age>b.age;
}
inline void make_new_ant(){
if(object[0][0])return;
++newborn;
but[++cnt]=*(new ant);
object[0][0]=1;
}
inline bool all_act(){
if(cnt<6)make_new_ant();
sort(but+1,but+cnt+1,cmp_age);
for(int i=1;i<=cnt;++i)but[i].leave_pheromone();
for(int i=1;i<=cnt;++i)but[i].move(),but[i].attack();
for(int i=1;i<=s;++i)tow[i].attack();
sort(but+1,but+cnt+1,cmp_HP);
for(int i=cnt;i>0;--i){
if(but[i].HP<0){
if(but[i].takingcake)but[i].takingcake=caketaken=0;
object[but[i].posx][but[i].posy]=0;
--cnt;
}
else
if(but[i].takingcake&&!but[i].posx&&!but[i].posy)return false;
}
for(int i=0;i<=n;++i)
for(int j=0;j<=m;++j)
if(pheromone[i][j])
--pheromone[i][j];
for(int i=1;i<=cnt;++i)++but[i].age;
return true;
}
int main(){
freopen("antbuster_ex.in","r",stdin);
freopen("antbuster_ex.out","w",stdout);
n=read(),m=read(),s=read(),d=read(),r=read();
for(int i=1;i<=s;++i)tow[i].x=read(),tow[i].y=read(),object[tow[i].x][tow[i].y]=1;
t=read();
for(int i=1;i<=t;++i){
if(!all_act()){
sort(but+1,but+cnt+1,cmp_age);
printf("Game over after %d seconds\n",i);
printf("%d\n",cnt);
for(int i=1;i<=cnt;++i)printf("%d %d %d %d %d\n",but[i].age-1,but[i].level,but[i].HP,but[i].posx,but[i].posy);
return 0;
}
}
sort(but+1,but+cnt+1,cmp_age);
puts("The game is going on");
printf("%d\n",cnt);
for(int i=1;i<=cnt;++i)printf("%d %d %d %d %d\n",but[i].age-1,but[i].level,but[i].HP,but[i].posx,but[i].posy);
}