题目有点长,这里直接扔个链接:#6619. 「THUPC 2019」鸭棋 / duckchess
鸭的移动可以这样处理:
bool ck6(ps u,ps v){
if(!((abs(v.x-u.x)==2&&abs(v.y-u.y)==3)||(abs(v.x-u.x)==3&&abs(v.y-u.y)==2)))return 0;
int f1=(u.x-v.x)/abs(u.x-v.x),f2=(u.y-v.y)/abs(u.y-v.y);
jk(i,1,2){v.x+=f1,v.y+=f2;if(wh(v).id)return 0;}
return 1;
}
这样就比较好些
其他似乎也没啥需要注意的了。。就是不要手滑 认真写代码就能
代码:
#include<bits/stdc++.h>
#define int long long
#define jk(i,j,k) for(int i=(j);i<=(k);i++)
#define kj(i,j,k) for(int i=(j);i>=(k);i--)
int rd(){int da=0;char ch=0,w=1;while(ch!='-'&&(ch>'9'||ch<'0'))ch=getchar();(ch=='-')&&(w=-1,ch=getchar());while(ch>='0'&&ch<='9'){da=da*10+ch-'0';ch=getchar();}return da*w;}
void P(int v){if(v<0){putchar('-');v=-v;}if(v>9)P(v/10);putchar(v%10+'0');}
const int dx[9]={0,2,1,-1,-2,-2,-1,1,2},dy[9]={0,1,2,2,1,-1,-2,-2,-1};
const int qx[9]={0,1,0,0,-1,-1,0,0,1},qy[9]={0,0,1,1,0,0,-1,-1,0};
struct ps{int x,y;};
struct No{int id,be;}MAP[15][15],lsk;
No wh(ps x){return MAP[x.x][x.y];}
bool ofr(ps p){return p.x>8||p.x<0||p.y>9||p.y<0;}
std::string st[10],cn;
void mini(){
st[1]="captain";st[2]="guard";st[3]="elephant";st[4]="horse";st[5]="car";st[6]="duck";st[7]="soldier";
// st[0]=" ";st[1]="王";st[2]="士";st[3]="象";st[4]="马";st[5]="车";st[6]="鸭";st[7]="兵";
jk(i,0,4)MAP[i*2][6]=(No){7,1};
jk(i,0,4)MAP[i*2][3]=(No){7,2};
MAP[0][0]=(No){5,2};MAP[1][0]=(No){4,2};MAP[2][0]=(No){3,2};MAP[3][0]=(No){2,2};MAP[4][0]=(No){1,2};MAP[5][0]=(No){2,2};MAP[6][0]=(No){3,2};MAP[7][0]=(No){4,2};MAP[8][0]=(No){5,2};
MAP[0][2]=(No){6,2};MAP[8][2]=(No){6,2};
MAP[0][9]=(No){5,1};MAP[1][9]=(No){4,1};MAP[2][9]=(No){3,1};MAP[3][9]=(No){2,1};MAP[4][9]=(No){1,1};MAP[5][9]=(No){2,1};MAP[6][9]=(No){3,1};MAP[7][9]=(No){4,1};MAP[8][9]=(No){5,1};
MAP[0][7]=(No){6,1};MAP[8][7]=(No){6,1};
}
#define KILL if(!r)return 0;\
if(MAP[v.x][v.y].id)ki=1,lsk=MAP[v.x][v.y];\
MAP[v.x][v.y]=MAP[u.x][u.y];MAP[u.x][u.y].id=MAP[u.x][u.y].be=0;\
return 1
bool ck1(ps u,ps v){return (abs(u.x-v.x)==1&&u.y==v.y)||(abs(u.y-v.y)==1&&u.x==v.x);}
bool ck2(ps u,ps v){return (abs(u.x-v.x)==1)&(abs(u.y-v.y)==1);}
bool ck3(ps u,ps v){return (abs(u.x-v.x)==2)&&(abs(u.y-v.y)==2)&&(MAP[(u.x+v.x)>>1][(u.y+v.y)>>1].id==0);}
bool ck7(ps u,ps v){return (abs(u.x-v.x)<=1)&&(abs(u.y-v.y)<=1);}
bool ck4(ps u,ps v){jk(i,1,8)if(!ofr((ps){u.x+dx[i],u.y+dy[i]})&&(v.x==u.x+dx[i]&&v.y==u.y+dy[i])&&(MAP[u.x+qx[i]][u.y+qy[i]].id==0))return 1;return 0;}
bool ck5(ps u,ps v){
if(abs(u.x-v.x)&&abs(u.y-v.y))return 0;
if(abs(u.x-v.x)+abs(u.y-v.y)==1)return 1;
else if(u.x==v.x){
if(u.y>v.y)jk(i,v.y+1,u.y-1)if(MAP[u.x][i].id)return 0;
if(u.y<v.y)jk(i,u.y+1,v.y-1)if(MAP[u.x][i].id)return 0;
}else if(u.y==v.y){
if(u.x>v.x)jk(i,v.x+1,u.x-1)if(MAP[i][u.y].id)return 0;
if(u.x<v.x)jk(i,u.x+1,v.x-1)if(MAP[i][u.y].id)return 0;
}
return 1;
}
bool ck6(ps u,ps v){
if(!((abs(v.x-u.x)==2&&abs(v.y-u.y)==3)||(abs(v.x-u.x)==3&&abs(v.y-u.y)==2)))return 0;
int f1=(u.x-v.x)/abs(u.x-v.x),f2=(u.y-v.y)/abs(u.y-v.y);
jk(i,1,2){v.x+=f1,v.y+=f2;if(wh(v).id)return 0;}
return 1;
}
bool ck(int id,ps u,ps v){
switch(id){
case 1:return ck1(u,v);
case 2:return ck2(u,v);
case 3:return ck3(u,v);
case 4:return ck4(u,v);
case 5:return ck5(u,v);
case 6:return ck6(u,v);
case 7:return ck7(u,v);
}
return 0;
}
bool C(int id,ps u,ps v,int&ki){int r=ck(id,u,v);KILL;}
void otp(No p,int ki,int prk,int end){
printf(p.be==1?"blue ":"red ");
std::cout<<st[p.id]<<";";
if(ki){
printf(lsk.be==1?"blue ":"red ");
std::cout<<st[lsk.id]<<";";
}else printf("NA;");
printf(prk?"yes;":"no;");
printf(end?"yes\n":"no\n");
}
bool GG(int pl){
ps H=(ps){10,10};jk(i,0,8)jk(j,0,9)if(MAP[i][j].id==1&&MAP[i][j].be==pl){H=(ps){i,j};break;}
// printf("found(%lld %lld),be=%lld\n",H.x,H.y,wh(H).be);
jk(i,0,8)jk(j,0,9){
if(MAP[i][j].be==pl)continue;
if(ck(MAP[i][j].id,(ps){i,j},H)){
// printf("pl=%lld id=%lld be=%lld (%lld,%lld)->(%lld,%lld)\n",pl,MAP[i][j].id,MAP[i][j].be,i,j,H.x,H.y);
return 1;
}
}
return 0;
}
void debug(){kj(j,9,0){jk(i,0,8)std::cout<<st[MAP[i][j].id];putchar('\n');}putchar('\n');}
signed main(){
mini();
int Q=rd();ps u,v;int be=2,ki=0,ok=0,END=0,B;//RED begin
// debug();
jk(QI,1,Q){
if(END){puts("Invalid command");continue;}
u.y=rd();u.x=rd();v.y=rd();v.x=rd();ki=0;B=be;
// puts("=====================================");
// printf("BE:%lld u(%lld,%lld): be=%lld id=%lld\n",be,u.x,u.y,wh(u).be,wh(u).id);
// printf("BE:%lld v(%lld,%lld): be=%lld id=%lld\n",be,v.x,v.y,wh(v).be,wh(v).id);
if(ofr(u)||ofr(v)||wh(u).be!=be||wh(v).be==be){puts("Invalid command");continue;}
int k=wh(u).id;
be=((ok=C(k,u,v,ki))?(be==2?1:2):be);
// debug();
if(lsk.id==1)END=1;
if(ok)otp(wh(ok?v:u),ki,GG(2)|GG(1),END);
else puts("Invalid command");
}
}