大模拟。
什么都不想补了。
看变量名感性理解吧
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; typedef double db; int n,m,t,s,d,gg,taken; db r; int R,mes[9][9],vis[9][9],target; db hp_up=1; int lev_up,tt; struct Poi{ int x,y; Poi(int A=0,int B=0):x(A),y(B){} Poi operator + (Poi &G){return Poi(x+G.x,y+G.y);} Poi operator - (Poi &G){return Poi(x-G.x,y-G.y);} bool operator != (Poi &G){return x!=G.x||y!=G.y;} bool in(){return x>=0&&x<=n&&y>=0&&y<=m;} void print(){printf("%d %d ",x,y);} }b[23]; Poi di[4]={Poi(0,1),Poi(1,0),Poi(0,-1),Poi(-1,0)}; struct ant{ int age,hp,lim,lev,cake; Poi id,ls; void born(){hp=lim=4*hp_up,lev=lev_up,age=1,id=ls=Poi(0,0);cake=0;} void print(){printf("%d %d %d %d %d ",age,lev,hp,id.x,id.y);} }a[9]; int dcmp(db x){return fabs(x)<1e-5?0:(x>0?1:-1);} db Dot(Poi A,Poi B){return A.x*B.x+A.y*B.y;} db Cross(Poi A,Poi B){return A.x*B.y-A.y*B.x;} db dis(Poi A){return sqrt(Dot(A,A));} db dis2(Poi A,Poi B,Poi C){ Poi v1=A-B,v2=C-B,v3=A-C; if(dcmp(Dot(v1,v2))<0) return dis(v2); if(dcmp(Dot(v2,v3))<0) return dis(v3); return fabs(Cross(v1,v3))/dis(v1); } void born(){if(tt%6==0) hp_up*=1.1,++lev_up; ++tt;a[++R].born();vis[0][0]=1;} void remain(int i){mes[a[i].id.x][a[i].id.y]+=a[i].cake?5:2;} #define to (a[i].id+di[j]) void take(int i){ if(a[i].id.x==n&&a[i].id.y==m&&!taken) taken=1,a[i].hp=min(a[i].lim,a[i].hp+a[i].lim/2),a[i].cake=1; } void move(int i){ bool nx=1,same=1; int me[4],mx=-1,dir=0; for(int j=0;j<4;++j) if(to.in()&&!vis[to.x][to.y]&&to!=a[i].ls){ me[j]=mes[to.x][to.y]; if(me[j]>mx) mx=me[j],dir=j,same=0; else if(me[j]==mx) same=1; } if(mx==-1) {a[i].ls=a[i].id;take(i);return ;} vis[a[i].id.x][a[i].id.y]=0; if(same){ for(int j=0;j<4;++j) if(mx==me[j]&&to.in()&&!vis[to.x][to.y]&&to!=a[i].ls) {dir=j; break;} } if(a[i].age%5==0){ for(int j=dir-1;nx&&j>=0;--j) if(to.in()&&!vis[to.x][to.y]&&to!=a[i].ls) nx=0,dir=j; for(int j=3;nx&&j>=dir;--j) if(to.in()&&!vis[to.x][to.y]&&to!=a[i].ls) nx=0,dir=j; } a[i].ls=a[i].id; a[i].id=a[i].id+di[dir]; vis[a[i].id.x][a[i].id.y]=1; take(i); } void over(int i){ if(a[i].id.x==0&&a[i].id.y==0&&a[i].cake){gg=1; return;} } void shoot(int i){ db len=dis(b[i]-a[target].id); if(taken&&len<=r){ for(int j=1;j<=R;++j) if(j==target||dis2(b[i],a[target].id,a[j].id)<=0.5) a[j].hp-=d; }else{ db mn=r; int ad=-1; for(int j=R;j>=1;--j){ len=dis(b[i]-a[j].id); if(len<=mn) mn=len,ad=j; } if(ad>0) a[ad].hp-=d; } } void check(int i){ if(a[i].hp<0){ if(a[i].cake) taken=0; vis[a[i].id.x][a[i].id.y]=0; for(int j=i;j<=R;++j) a[j]=a[j+1]; --R; }else ++a[i].age; } void disappear(){ for(int i=0;i<=n;++i) for(int j=0;j<=m;++j) if(mes[i][j]) --mes[i][j]; } int main(){ scanf("%d%d%d%d%lf",&n,&m,&s,&d,&r); for(int i=1;i<=s;++i) scanf("%d%d",&b[i].x,&b[i].y),vis[b[i].x][b[i].y]=1; scanf("%d",&t); for(int i=1,j;i<=t;++i){ if(!vis[0][0]&&R<6) born(); for(j=1;j<=R;++j) remain(j); for(j=1;j<=R;++j) move(j); for(j=1;j<=R;++j) if(a[j].cake) taken=1,target=j; for(j=1;j<=s;++j) shoot(j); for(j=R;j;--j) check(j); for(j=1;j<=R;++j) over(j); if(gg){printf("Game over after %d seconds ",i); break;} disappear(); } if(!gg) puts("The game is going on"); printf("%d ",R); for(int i=1;i<=R;++i) a[i].age-=1+gg,a[i].print(); return 0; }