[ZJOI2008]杀蚂蚁 Solution
题目太长,不在此显示,见洛谷P2586
http://daniu.luogu.org/problem/show?pid=2586
模拟,
那就模拟呗;
各种WA,
然后好久才A了;
一种被社会报复了的感觉
好像被蚂蚁踩死了
代码能力太差
唉,正题:
整体流程:
1.蚂蚁出生;
2.放信息素;
3.到处乱跑;
4.被弄死;
5.结算;
6.(神允许)时间流动;
然后是一些细节:
1.输出的蚂蚁年龄,把刚出生的蚂蚁视为0岁,直到一次时间流动后才是1岁,然而与移动方向相关的年龄视刚出生的蚂蚁为1岁
2.可以伪链式存储蚂蚁,以方便查询
3.对于一只蚂蚁,如果她要移动,则不能移动回上回合呆的地方(上上回合呆的地方可以)
4.不移动的蚂蚁也有可能变成target----(上回合的target挂了,然后这只蚂蚁被卡在(n,m)点)
5.炮塔选定目标时,把蚂蚁看为点,然而结算一次攻击的波及范围时,把蚂蚁看做圆
6.半径0.5
7.炮塔同时选目标,同时攻击
8.仔细阅读如下文字:“只要目标在其射程内,塔到目标蚂蚁圆心的连线上的所有蚂蚁......”好像是说如果目标不在射程内,谁也不会被攻击
9.其他一些,诸如,信息素别减爆、血量别加超,之类的;
代码如下:(因为没有重构,所以代码十分难看)
1 #include<cstdio> 2 using namespace std; 3 struct ANT{ 4 int x,y,time,blo,blo_up,lv,lx,ly,next; 5 bool cake; 6 }; 7 struct Tour{ 8 int x,y; 9 }; 10 ANT ant[200010]; 11 int tot,many,target,top=0; 12 Tour tour[22]; 13 int n,m,s,d,r,t; 14 int ma_su[10][10]; 15 int ma_th[10][10]; 16 int xx[4]={0,1,0,-1}; 17 int yy[4]={1,0,-1,0}; 18 void Init(); 19 void work(); 20 void born(); 21 double Sqr(int ); 22 void put_su(); 23 void run(); 24 void hurt(); 25 bool cmp(int ,int ,int ,int ,int ,int ); 26 bool check(); 27 void print(); 28 int main() 29 { 30 Init(); 31 work(); 32 } 33 void Init(){ 34 int i,j,k; 35 scanf("%d%d",&n,&m); 36 scanf("%d%d%d",&s,&d,&r); 37 for(i=1;i<=s;i++){ 38 scanf("%d%d",&tour[i].x,&tour[i].y); 39 ma_th[tour[i].x][tour[i].y]=-1; 40 } 41 scanf("%d",&t); 42 tot=many=target=0; 43 return ; 44 } 45 void work(){ 46 int i,j,T=0; 47 while(++T<=t){ 48 born(); 49 put_su(); 50 run(); 51 hurt(); 52 if(check()){ 53 printf("Game over after %d seconds\n",T); 54 print(); 55 return; 56 } 57 for(i=0;i<=n;i++) 58 for(j=0;j<=m;j++) 59 ma_su[i][j]-=(ma_su[i][j]!=0?1:0); 60 for(i=1;i<=tot;i++) 61 ant[i].time++; 62 } 63 printf("The game is going on\n"); 64 print(); 65 return; 66 } 67 void born(){ 68 if(!ma_th[0][0]&&many<6){ 69 ant[top].next=++tot; 70 ant[tot].lv=(tot-1)/6+1; 71 ant[tot].blo=ant[tot].blo_up=int(4*Sqr(ant[tot].lv)); 72 ant[tot].time=0; 73 ant[tot].x=ant[tot].y=0;ant[tot].lx=ant[tot].ly=-1; 74 ma_th[0][0]=tot; 75 many++; 76 top=tot; 77 } 78 } 79 double Sqr(int m){ 80 double ans=1,x=1.1; 81 while(m){ 82 if(m&1) 83 ans*=x; 84 m>>=1; 85 x*=x; 86 } 87 return ans; 88 } 89 void put_su(){ 90 int i; 91 for(i=1;i<=tot;i++) 92 if(ant[i].blo>=0) 93 ma_su[ant[i].x][ant[i].y]+=(ant[i].cake?5:2); 94 } 95 void run(){ 96 int i,j,k,fx,X,Y,max; 97 for(i=ant[0].next;i;i=ant[i].next){ 98 fx=-1;max=-1; 99 for(j=0;j<=3;j++){ 100 X=ant[i].x+xx[j]; 101 Y=ant[i].y+yy[j]; 102 if(X<=n&&X>=0&&Y<=m&&Y>=0&&(X!=ant[i].lx||Y!=ant[i].ly)&&(!ma_th[X][Y])&&ma_su[X][Y]>max){ 103 max=ma_su[X][Y]; 104 fx=j; 105 } 106 } 107 if(fx!=-1){ 108 if(!((ant[i].time+1)%5)) 109 for(j=1;j<=4;j++){ 110 fx=(fx+4-1)%4; 111 X=ant[i].x+xx[fx]; 112 Y=ant[i].y+yy[fx]; 113 if(X<=n&&X>=0&&Y<=m&&Y>=0&&(X!=ant[i].lx||Y!=ant[i].ly)&&(!ma_th[X][Y])) 114 break; 115 } 116 ma_th[ant[i].x][ant[i].y]=0; 117 ant[i].lx=ant[i].x;ant[i].ly=ant[i].y; 118 ant[i].x+=xx[fx];ant[i].y+=yy[fx]; 119 } 120 else{ 121 ant[i].lx=-1; 122 ant[i].ly=-1; 123 } 124 if(ant[i].x==n&&ant[i].y==m&&!target){ 125 target=i; 126 ant[i].cake=true; 127 ant[i].blo=ant[i].blo+ant[i].blo_up/2<ant[i].blo_up?ant[i].blo+ant[i].blo_up/2:ant[i].blo_up; 128 } 129 ma_th[ant[i].x][ant[i].y]=i; 130 } 131 } 132 void hurt(){ 133 int i,j,k,len,targ=-1,X,Y; 134 for(i=1;i<=s;i++){ 135 X=ant[target].x-tour[i].x;Y=ant[target].y-tour[i].y; 136 if(!target||X*X+Y*Y>r*r){ 137 len=10010; 138 for(j=ant[0].next;j;j=ant[j].next) 139 if((tour[i].x-ant[j].x)*(tour[i].x-ant[j].x)+(tour[i].y-ant[j].y)*(tour[i].y-ant[j].y)<len){ 140 targ=j;len=(tour[i].x-ant[j].x)*(tour[i].x-ant[j].x)+(tour[i].y-ant[j].y)*(tour[i].y-ant[j].y); 141 } 142 } 143 else 144 targ=target; 145 X=ant[targ].x-tour[i].x;Y=ant[targ].y-tour[i].y; 146 if(X*X+Y*Y<=r*r) 147 for(j=ant[0].next;j;j=ant[j].next) 148 if(cmp(ant[j].x,ant[j].y,tour[i].x,tour[i].y,ant[targ].x,ant[targ].y)) 149 ant[j].blo-=d; 150 } 151 j=0; 152 for(i=ant[j].next;i;i=ant[i].next) 153 if(ant[i].blo<0){ 154 ma_th[ant[i].x][ant[i].y]=0;many--; 155 ant[j].next=ant[i].next; 156 if(i==target) 157 ant[i].cake=false; 158 if(i==top) 159 top=j; 160 } 161 else 162 j=i; 163 if(!ant[target].cake) 164 target=0; 165 } 166 bool cmp(int ax,int ay,int tx,int ty,int targx,int targy){ 167 double t_ax=ax-tx,t_ay=ay-ty,targ_ax=ax-targx,targ_ay=ay-targy,t_targx=targx-tx,t_targy=targy-ty; 168 double R=(t_ax*t_targx+t_ay*t_targy)/(t_targx*t_targx+t_targy*t_targy); 169 if(R<=0)return (t_ax*t_ax+t_ay*t_ay)<=0.25; 170 if(R>=1)return (targ_ax*targ_ax+targ_ay*targ_ay)<=0.25; 171 double px=tx+(targx-tx)*R; 172 double py=ty+(targy-ty)*R; 173 return (ax-px)*(ax-px)+(ay-py)*(ay-py)<=0.25; 174 } 175 bool check(){ 176 return (target&&!ant[target].x&&!ant[target].y); 177 } 178 void print(){ 179 int i; 180 printf("%d\n",many); 181 for(i=ant[0].next;i;i=ant[i].next) 182 printf("%d %d %d %d %d\n",ant[i].time,ant[i].lv,ant[i].blo,ant[i].x,ant[i].y); 183 }
祝AC
Just close your eyes, you`ll be alright, no one can hurt you after you die.