cdcq

梦幻小鱼干

导航

【ICPC2019南昌站】I - Resistance

原题:

 

 

 

 

 

 题面太长了,我就不翻译了

 

 

大模拟,题意模拟出来即可过

看上去很模拟,其实并不复杂,游戏逻辑还是很简单的

写法:只需用一个结构体记录僵尸的所有状态,然后每次枚举僵尸和炮台去操作,不用画在地图上,如果移走(死或者达阵)就别动了,这样输出的时候就可以直接根据状态输出

细节:

1.枪塔的冷却时间需要注意,容易写错(如果你判断找不到目标就直接return的话,那么可能会在没有目标的情况下没有冷却)

2.注意是欧几里得距离,不是曼哈顿距离,如果你为了避免小数判断而使用距离的平方,那么r1和r2也要平方

3.如果按出场时间递增枚举僵尸的话,选择僵尸的时候只需当前距离小于之前最优距离即可,这样会自动选择离村子最近的(注意不是<=,编号越大代表距离越远,不要想错了)

4.被喷火器喷的僵尸要到下一帧才开始燃烧,注意读题

5.如果燃烧的僵尸被续杯了,那么续杯的当帧也是要燃烧的

自信满满地以为能1A,结果还是WA了好几发,惭愧,惭愧啊

 

代码:

  1 #include<iostream>
  2 #include<cstdio>
  3 using namespace std;
  4 struct nds{
  5     int x,y;
  6     int hp,tp;
  7     int id,st;
  8     int fr;
  9 };
 10 int n,m,L,E,T;
 11 nds a[410];
 12 int r1,d1,t1,r2,d2,t2,d3;
 13 int hp1,hp2,def;
 14 nds b[410],c[410];
 15 char s[410];
 16 int ans[410];
 17 void fwd(){
 18     for(int i=1;i<=E;++i)if(c[i].st==1){
 19         c[i].id++;
 20         c[i].x=a[c[i].id].x,c[i].y=a[c[i].id].y;
 21     }
 22 }
 23 void dmg(int x,int y){  c[x].hp-=(c[x].tp==1 ? y : max(1,y-def));}
 24 inline int sqr(int x){  return x*x;}
 25 int dst(nds x,nds y){  return sqr(x.x-y.x)+sqr(x.y-y.y);}
 26 void fir(int x){
 27     if(b[x].tp==1 && b[x].st>0){
 28         b[x].st--;
 29         return; 
 30     }
 31     int mn=0;
 32     for(int i=1;i<=E;++i)if(c[i].st==1){
 33         if(!mn || dst(b[x],c[i])<dst(b[x],c[mn]))
 34             if(dst(b[x],c[i])<=(b[x].tp==1 ? r1*r1 : r2*r2))  mn=i;
 35     }
 36     if(!mn)  return ;
 37     if(b[x].tp==1 && b[x].st==0){
 38         dmg(mn,d1);
 39         b[x].st=t1-1;
 40     }
 41     else if(b[x].tp==2){
 42         dmg(mn,d2);
 43         c[mn].fr=(c[mn].fr>0 ? t2+1 : -(t2+1));
 44     }
 45 }
 46 void brn(){
 47     for(int i=1;i<=E;++i)if(c[i].st==1)
 48         if(c[i].fr!=0){
 49             if(c[i].fr<0)  c[i].fr=-c[i].fr;
 50             else  c[i].hp-=d3;
 51             c[i].fr--;
 52         }
 53 }
 54 void rmv(int x){
 55     for(int i=1;i<=E;++i)if(c[i].st==1){
 56         if(c[i].hp<0){
 57             c[i].st=0;
 58             ans[i]=-x;
 59         }
 60         else if(c[i].id==L){
 61             c[i].st=0;
 62             ans[i]=2;
 63         }
 64     }
 65 }
 66 int main(){
 67     int S;  cin>>S;
 68     for(int t=1;t<=S;++t){
 69         scanf("%d%d%d%d%d",&n,&m,&L,&E,&T);
 70         for(int i=1;i<=L;++i)  scanf("%d%d",&a[i].x,&a[i].y);
 71         scanf("%d%d%d%d%d%d%d",&r1,&d1,&t1,&r2,&d2,&t2,&d3);
 72         scanf("%d%d%d",&hp1,&hp2,&def);
 73         for(int i=1;i<=m;++i){
 74             scanf("%d%d%d",&b[i].tp,&b[i].x,&b[i].y);
 75             b[i].st=0;
 76         }
 77         scanf("%s",s+1);
 78         for(int i=1;i<=E;++i){
 79             c[i].tp=s[i]-'0';
 80             c[i].x=a[1].x,c[i].y=a[1].y;
 81             c[i].hp=(c[i].tp==1 ? hp1 : hp2);
 82             c[i].id=0,c[i].st=0;
 83             c[i].fr=0;
 84             ans[i]=0;
 85         }
 86         for(int k=1;k<=T;++k){
 87             fwd();
 88             if(k<=E){
 89                 c[k].st=1;
 90                 c[k].id=1;
 91             }
 92             for(int i=1;i<=m;++i)  fir(i);
 93             brn();
 94             rmv(k);
 95         }
 96         printf("Case #%d:\n",t);
 97         for(int i=1;i<=E;++i){
 98             if(ans[i]==2)  printf("Arrive with %d HP(s).\n",c[i].hp);
 99             else if(ans[i]<0)
100                 printf("Be killed in the %d-th frame at (%d,%d).\n",
101                         -ans[i],c[i].x,c[i].y);
102             else
103                 printf("Be alive at (%d,%d) with %d HP(s).\n",
104                         c[i].x,c[i].y,c[i].hp);
105         }
106     }
107     return 0;
108 }
View Code

 

posted on 2020-11-27 21:33  cdcq  阅读(177)  评论(0编辑  收藏  举报