P5380的代码
inoichi_lim
2020-05-18 16:17:41
# Day1 2020年5月18日16:16:18
今天莫名其妙地想写一道大$\%$你,于是开始写起了P5380……
然后这篇文章就用来记录咯。~~(说好的$200$粉才去呢~~
代码:
```cpp
#include<bits/stdc++.h>
#define ns "Invalid command\n"
#define fs(i,x,y,z) for(ll i=x;i<=y;i+=z)
#define ft(i,x,y,z) for(ll i=x;i>=y;i+=z)
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=11,inf=0x3f3f3f3f;
const char homo[N][N]={"","captain","guard","elephant","horse","car","duck","soldier"},color[2][5]={"red","blue"};
inline int read(){
int date=0,w=1;char c=0;
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}
return date*w;
}
void qipan(){
/*
80 81 82 83 84 85 86 87 88
70 71 72 73 74 75 76 77 78
60 61 62 63 64 65 66 67 68
50 51 52 53 54 55 56 57 58
40 41 42 43 44 45 46 47 48
30 31 32 33 34 35 36 37 38
20 21 22 23 24 25 26 27 28
10 11 12 13 14 15 16 17 18
00 01 02 03 04 05 06 07 08
*/
}
//0空1王2士3象4马5车6鸭7兵
struct qizi{
int type,x,y;
bool color,live;
qizi(){
type=0;
color=0,live=0;
}
bool walk(int wantx,int wanty){
if(type==1){
}else if(type==2){
}else if(type==3){
}else if(type==4){
}else if(type==5){
}else if(type==6){
}else if(type==7){
}
return 0;
}
void setup(int ttype,int xx,int yy,bool clr){
type=ttype;
x=xx;y=yy;
color=clr;
live=1;
}
void fpgz(){
type=0,live=0,color=0;
}
}a[N][N],killed;
int l,sx,sy,ex,ey;
bool ongame=1,jiang,killen;
bool run(int sx,int sy,int ex,int ey){
if(a[sx][sy].type==0||!ongame) return 0;
return a[sx][sy].walk(ex,ey);
}
void pr(int x,int y){
//打印是什么棋子;
printf("%s %s,",color[a[x][y].color],homo[a[x][y].type]);
//打印有没有杀
if(killen){
printf("%s %s,",color[killed.color],homo[killed.type]);
}else printf("NA,");
//打印有没有将军
if(jiang){
printf("yes,");
}else printf("no,");
//打印有没有结束
if(!ongame){
printf("yes\n");
}else printf("no\n");
}
void setups(){//暴力初始化棋盘
//红的底
a[0][0].setup(5,0,0,0);a[0][1].setup(4,0,1,0);a[0][2].setup(3,0,2,0);
a[0][3].setup(2,0,3,0);a[0][4].setup(1,0,4,0);a[0][5].setup(2,0,5,0);
a[0][6].setup(3,0,6,0);a[0][7].setup(4,0,7,0);a[0][8].setup(5,0,8,0);
//蓝的底
a[9][0].setup(5,9,0,1);a[9][1].setup(4,9,1,1);a[9][2].setup(3,9,2,1);
a[9][3].setup(2,9,3,1);a[9][4].setup(1,9,4,1);a[9][5].setup(2,9,5,1);
a[9][6].setup(3,9,6,1);a[9][7].setup(4,9,7,1);a[9][8].setup(5,9,8,1);
//红炮
a[2][0].setup(6,2,0,0);a[2][8].setup(6,2,8,0);
//蓝炮
a[7][0].setup(6,7,0,1);a[7][8].setup(6,7,8,1);
//红兵
a[3][0].setup(7,3,0,0);a[3][2].setup(7,3,2,0);a[3][4].setup(7,3,4,0);
a[3][6].setup(7,3,6,0);a[3][8].setup(7,3,8,0);
//蓝兵
a[6][0].setup(7,6,0,1);a[6][2].setup(7,6,2,1);a[6][4].setup(7,6,4,1);
a[6][6].setup(7,6,6,1);a[6][8].setup(7,6,8,1);
}
int main(){
l=read();
setups();
fs(i,0,9,1){
fs(j,0,8,1){
a[i][j].x=i;
a[i][j].y=j;
}
}
fs(sf,1,l,1){
jiang=0,killen=0;
sx=read(),sy=read(),ex=read(),ey=read();
if(run(sx,sy,ex,ey)==0) printf(ns);
else pr(ex,ey);
}
return 0;
}
```
简单讲一下。
这里首先读入操作数$l$,初始化坐标。
`qizi`的意思是对于这个坐标,你上面的棋子是什么属性的。~~众所周知空的话是不算活的~~
然后先暴力初始化(按题目要求,这里`setups`就是初始化函数)
然后`qipan`是空函数,存了棋盘。
`pr`是如果合法的话的按规则的打印函数。
`run`就是移动函数,$1$合法再带上动的,$0$不合法,还有`jiang`就是有没有将军,`killen`有没有杀人,如果有的话存`killed`。
`run`的方法就是对于整个棋盘,直接暴力。