标签:
#include<set> #include<map> #include<cmath> #include<ctime> #include<deque> #include<queue> #include<bitset> #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define LL long long #define inf 0x7fffffff #define pa pair<int,int> #define pi 3.1415926535897932384626433832795028841971 using namespace std; const int mx[4]={1,0,-1,0}; const int my[4]={0,1,0,-1}; struct ant{ int age,level,x,y,hp,mhp; bool cake,dead; }a[200010];int antl=1,antr; int n,m,battery,damage,range;//µØͼ³¤¡¢¿í£¬ÅŲ́¸öÊý£¬É˺¦£¬¹¥»÷·¶Î§ int T,nowt,totant,nowant; bool gameover,cakecarried; int mp[10][10];//-1±íʾ²»¿ÉÐÐ int message[10][10]; inline void init() { scanf("%d%d",&n,&m); scanf("%d%d%d",&battery,&damage,&range); for (int i=1;i<=battery;i++) { int dx,dy;scanf("%d%d",&dx,&dy); mp[dx][dy]=-1; } scanf("%d",&T); } inline void printout() { if (gameover) {printf("Game over after %d seconds\n",nowt);return;} printf("The game is going on\n"); for (int i=antl;i<=antr;i++) if (!a[i].dead)printf("%d %d %d %d %d\n",a[i].age,a[i].level,a[i].hp,a[i].x,a[i].y); } inline void lvlup() { for (int i=antl;i<=antr;i++)if (!a[i].dead)a[i].age++; } inline void givebirth() { if (nowant>=6||mp[0][0]==-1)return; antr++;totant++;nowant++; a[antr].age=1; a[antr].x=a[antr].y=0; mp[0][0]=-1; a[antr].level=(totant+5)/6; a[antr].mhp=a[antr].hp=(int) 4*pow(1.1,a[antr].level); a[antr].cake=a[antr].dead=0; } inline void leave_message() { for (int i=antl;i<=antr;i++) if (!a[i].dead) message[a[i].x][a[i].y]+=(a[i].cake?5:2); } inline void move(int na) { int nx,ny,alternative=0,sx,sy,sv; for (int k=3;k>=0;k--) { nx=a[na].x+mx[k];ny=a[na].y+my[k]; if (nx<0||nx>n||ny<0||ny>n||mp[nx][ny]==-1)continue; if (!alternative||alternative&&message[nx][ny]>message[sx][sy]) sv=k,sx=nx,sy=ny; alternative++; } if (!a[na].age%5) for(int i=sv;i>=sv-4;i--) { int k=(i+4)%4; nx=a[na].x+mx[k];ny=a[na].y+my[k]; if (nx<0||nx>n||ny<0||ny>n||mp[nx][ny]==-1)continue; sv=k;break; } mp[a[na].x][a[na].y]=0; a[na].x+=mx[sv];a[na].y+=my[sv]; mp[a[na].x][a[na].y]=-1; if(a[na].x==n&&a[na].y==m&&!cakecarried) {a[na].cake=1;a[na].hp=min(a[na].hp+a[na].mhp,a[na].mhp);cakecarried=1;} } inline bool judgedeath(int na) { if (a[na].hp>=0)return 1; a[na].dead=1;nowant--; if (na==antl)while (a[antl].dead&&antl<=antr)antl++; if (a[na].cake) { cakecarried=0; a[na].cake=0; } } inline void attack() { } inline bool judge_win() { for (int i=antl;i<=antr;i++) if (!a[i].dead&&a[i].x==n&&a[i].y==m&&a[i].cake) { gameover=1; return 1; } return 0; } inline void work() { lvlup(); givebirth(); leave_message(); for (int i=antl;i<=antr;i++)if (!a[i].dead)move(i); attack(); if(judge_win())return; } int main() { init(); for(nowt=1;nowt<=T;nowt++){work();if (gameover)break;} printout(); return 0; }
#include<set>#include<map>#include<cmath>#include<ctime>#include<deque>#include<queue>#include<bitset>#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#define LL long long#define inf 0x7fffffff#define pa pair<int,int>#define pi 3.1415926535897932384626433832795028841971using namespace std;const int mx[4]={1,0,-1,0};const int my[4]={0,1,0,-1};struct ant{int age,level,x,y,hp,mhp;bool cake,dead;}a[200010];int antl=1,antr;int n,m,battery,damage,range;//µØͼ³¤¡¢¿í£¬ÅŲ́¸öÊý£¬É˺¦£¬¹¥»÷·¶Î§int T,nowt,totant,nowant;bool gameover,cakecarried;int mp[10][10];//-1±íʾ²»¿ÉÐÐint message[10][10];inline void init(){scanf("%d%d",&n,&m);scanf("%d%d%d",&battery,&damage,&range);for (int i=1;i<=battery;i++){int dx,dy;scanf("%d%d",&dx,&dy);mp[dx][dy]=-1;}scanf("%d",&T);}inline void printout(){if (gameover){printf("Game over after %d seconds\n",nowt);return;}printf("The game is going on\n");for (int i=antl;i<=antr;i++)if (!a[i].dead)printf("%d %d %d %d %d\n",a[i].age,a[i].level,a[i].hp,a[i].x,a[i].y);}inline void lvlup(){for (int i=antl;i<=antr;i++)if (!a[i].dead)a[i].age++;}inline void givebirth(){if (nowant>=6||mp[0][0]==-1)return;antr++;totant++;nowant++;a[antr].age=1;a[antr].x=a[antr].y=0;mp[0][0]=-1;a[antr].level=(totant+5)/6;a[antr].mhp=a[antr].hp=(int) 4*pow(1.1,a[antr].level);a[antr].cake=a[antr].dead=0;}inline void leave_message(){for (int i=antl;i<=antr;i++)if (!a[i].dead)message[a[i].x][a[i].y]+=(a[i].cake?5:2);}inline void move(int na){int nx,ny,alternative=0,sx,sy,sv;for (int k=3;k>=0;k--){nx=a[na].x+mx[k];ny=a[na].y+my[k];if (nx<0||nx>n||ny<0||ny>n||mp[nx][ny]==-1)continue;if (!alternative||alternative&&message[nx][ny]>message[sx][sy])sv=k,sx=nx,sy=ny;alternative++;}if (!a[na].age%5)for(int i=sv;i>=sv-4;i--){int k=(i+4)%4;nx=a[na].x+mx[k];ny=a[na].y+my[k];if (nx<0||nx>n||ny<0||ny>n||mp[nx][ny]==-1)continue;sv=k;break;}mp[a[na].x][a[na].y]=0;a[na].x+=mx[sv];a[na].y+=my[sv];mp[a[na].x][a[na].y]=-1;if(a[na].x==n&&a[na].y==m&&!cakecarried){a[na].cake=1;a[na].hp=min(a[na].hp+a[na].mhp,a[na].mhp);cakecarried=1;}}inline bool judgedeath(int na){if (a[na].hp>=0)return 1;a[na].dead=1;nowant--;if (na==antl)while (a[antl].dead&&antl<=antr)antl++;if (a[na].cake){cakecarried=0;a[na].cake=0;}}inline void attack(){}inline bool judge_win(){for (int i=antl;i<=antr;i++)if (!a[i].dead&&a[i].x==n&&a[i].y==m&&a[i].cake){gameover=1;return 1;}return 0;}inline void work(){lvlup();givebirth();leave_message();for (int i=antl;i<=antr;i++)if (!a[i].dead)move(i);attack();if(judge_win())return;}int main(){init();for(nowt=1;nowt<=T;nowt++){work();if (gameover)break;}printout();return 0;}
#include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define inf 0x7fffffff #define eps 1e-8 using namespace std; const int mx[4]={0,1,0,-1}; const int my[4]={1,0,-1,0}; struct ant{ int age,level,x,y,hp,mhp;//ÄêÁ䣬µÈ¼¶£¬xy×ø±ê£¬ÑªÁ¿£¬×î´óѪÁ¿ bool cake,dead;//ÊÇ·ñÄÃ×ŵ°¸â£¬ÊÇ·ñÒÑËÀÍö }a[200010];int antl=1,antr;//¶ÓÁÐ×ó¡¢ÓÒ struct batt{int x,y;}b[100];//ÅŲ́ int n,m,battery,damage,range,tg;//µØͼ³¤¡¢¿í£¬ÅŲ́¸öÊý£¬É˺¦£¬¹¥»÷·¶Î§£¬ÅŲ́Ŀ±ê int T,nowt,totant,nowant;//ÒªÇóʱ¼ä£¬µ±Ç°Ê±¼ä£¬¹²Éú²ú¶àÉÙÂìÒÏ£¬µ±Ç°ÓжàÉÙÂìÒÏ bool gameover,cakecarried;//ÓÎÏ·½áÊø£¬µ°¸â±»È¡×ß int mp[10][10];//µØͼ£¬-1±íʾ²»¿É×ß int message[10][10];//ÐÅÏ¢ËØ inline void init() { scanf("%d%d",&n,&m); scanf("%d%d%d",&battery,&damage,&range); for (int i=1;i<=battery;i++) { scanf("%d%d",&b[i].x,&b[i].y); mp[b[i].x][b[i].y]=-1; } scanf("%d",&T); } inline void printout() { if (gameover) {printf("Game over after %d seconds\n",nowt);return;} printf("The game is going on\n%d\n",nowant); for (int i=antl;i<=antr;i++) if (!a[i].dead) printf("%d %d %d %d %d\n",a[i].age,a[i].level,a[i].hp,a[i].x,a[i].y); } inline void ageup() { for (int i=antl;i<=antr;i++)if (!a[i].dead)a[i].age++; } inline void givebirth() { if (nowant>=6||mp[0][0]==-1)return; antr++;totant++;nowant++; a[antr].age=a[antr].x=a[antr].y=0; mp[0][0]=-1; a[antr].level=(totant+5)/6; a[antr].mhp=a[antr].hp=(int) 4*pow(1.1,a[antr].level); a[antr].cake=a[antr].dead=0; } inline void leave_message() { for (int i=antl;i<=antr;i++) if (!a[i].dead) message[a[i].x][a[i].y]+=(a[i].cake?5:2); } inline void move(int na) { int nx,ny,alternative=0,sx,sy,sv; for (int k=3;k>=0;k--) { nx=a[na].x+mx[k];ny=a[na].y+my[k]; if (nx<0||nx>n||ny<0||ny>m||mp[nx][ny]==-1)continue; if (!alternative||alternative&&message[nx][ny]>=message[sx][sy]) sv=k,sx=nx,sy=ny; alternative++; } if (!alternative)return; if (a[na].age%5==0) for(int i=sv-1;i>=sv-4;i--) { int k=(i+4)%4; nx=a[na].x+mx[k];ny=a[na].y+my[k]; if (nx<0||nx>n||ny<0||ny>m||mp[nx][ny]==-1)continue; sv=k;break; } mp[a[na].x][a[na].y]=0; a[na].x+=mx[sv];a[na].y+=my[sv]; mp[a[na].x][a[na].y]=-1; if(a[na].x==n&&a[na].y==m&&!cakecarried) { a[na].cake=1; a[na].hp=min(a[na].hp+a[na].mhp,a[na].mhp); cakecarried=1; tg=na; } } inline bool judgedeath(int na) { if (a[na].hp>=0)return 0; a[na].dead=1;nowant--; if (na==antl)while (a[antl].dead&&antl<=antr)antl++; if (a[na].cake) { cakecarried=0; a[na].cake=0; tg=0; } return 1; } inline bool inrange(batt nb,ant na) { int sx=nb.x,sy=nb.y,tx=na.x,ty=na.y; return (sx-tx)*(sx-tx)+(sy-ty)*(sy-ty)>=range*range; } inline bool cross(batt nb,ant na,ant nc) { int A=na.y-nb.y,B=nb.x-na.x,C=na.x*nb.y+nb.x*na.y,sx=nc.x,sy=nc.y; if ((sx*A+sy*B+C)*(sx*A+sy*B+C)<=A*A+B*B)return 1; return 0; } inline void attack(batt nb) { int targ,dist=inf; if (cakecarried&&inrange(nb,a[tg]))targ=tg;else for (int i=antr;i>=antl;i--) { int dd=(nb.x-a[i].x)*(nb.y-a[i].y)+(nb.x-a[i].x)*(nb.y-a[i].y); if (dd<=dist){dist=dd;targ=i;} } a[targ].hp-=damage;judgedeath(targ); for (int i=antl;i<=antr;i++) { if(i==targ)continue; if(cross(nb,a[targ],a[i])) { a[i].hp-=damage; judgedeath(i); } } } inline bool judge_win() { for (int i=antl;i<=antr;i++) if (!a[i].dead&&a[i].cake&&a[i].x==0&&a[i].y==0) { gameover=1; return 1; } return 0; } inline void work() { givebirth(); ageup(); leave_message(); for (int i=antl;i<=antr;i++)if (!a[i].dead)move(i); //for (int i=1;i<=battery;i++)attack(b[i]); if(judge_win())return; } int main() { init(); for(nowt=1;nowt<=T;nowt++){work();if (gameover)break;} printout(); return 0; }
标签:
原文地址:http://www.cnblogs.com/zhber/p/4888644.html