1. 程式人生 > 實用技巧 >【ICPC2019南昌站】I - Resistance

【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