首页 技术 正文
技术 2022年11月20日
0 收藏 428 点赞 3,862 浏览 1320 个字

就是声明两个数组,一个模拟棋局,另一个模拟黑将不能走的位置。不过写得有点长了…

 #include<iostream> #include<string> using namespace std; struct Node {     ];     int x, y; }a[]; ][];  //模拟棋盘棋子的情况 ][];  //模拟黑棋不能走的情况 int bh, bs;       //黑色棋子的坐标 void G(int x, int y)                      //模拟帅棋子 {     ;     ; i < x; i++)     {         if (vis[i][y])         {             flag = ;             break;         }     }     )     {         cnt[][y] = ;         cnt[][y] = ;         cnt[][y] = ;     } } void R(int x, int y)                     //模拟车棋子 {     ;      && y < )     {         ; i < ; i++)         {             if (vis[x][i])             {                 flag = ;                 break;             }         }     }      && y>)     {         ; i < y; i++)         {             if (vis[x][i])             {                 flag = ;                 break;             }         }     }      && y <= )     {         ; i < y; i++)         {             if (vis[i][y])             {                 flag = ;                 break;             }         }     }     )     {         )         {             cnt[x][] = ;             cnt[x][] = ;             cnt[x][] = ;         }         )         {             cnt[][y] = ;             cnt[][y] = ;             cnt[][y] = ;         }     } } void C(int x, int y)                //模拟炮棋子 {     ;      && y < )     {         ; i < ; i++)         {             if (vis[x][i])             {                 cnt[x][] = ;                 cnt[x][] = ;                 cnt[x][] = ;                 break;             }         }     }      && y > )     {         ; i < y; i++)         {             if (vis[x][i])             {                 cnt[x][] = ;                 cnt[x][] = ;                 cnt[x][] = ;             }         }     }      && y >=  && y <= )     {         ; i < x; i++)         {             if (vis[i][y])             {                 cnt[][y] = ;                 cnt[][y] = ;                 cnt[][y] = ;             }         }     } }         void H(int x, int y)                      //模拟马棋子 {      > )     {         ][y])         {              > )             {                 cnt[x - ][y - ] = ;             }              < )             {                 cnt[x + ][y + ] = ;             }         }     }      < )     {         ][y])         {              > )             {                 cnt[x + ][y - ] = ;             }              < )             {                 cnt[x + ][y + ] = ;             }         }     }      > )     {         ])         {              > )             {                 cnt[x - ][y - ] = ;             }              < )             {                 cnt[x + ][y - ] = ;             }         }     }      < )     {         ])         {              > )             {                 cnt[x - ][y + ] = ;             }              < )             {                 cnt[x + ][y + ] = ;             }         }     } } int _tmain(int argc, _TCHAR* argv[]) {     int n;            //红色棋子的个数     while (cin >> n >> bh >> bs && n)     {         memset(vis, , sizeof(vis));         memset(cnt, , sizeof(cnt));         ; i < n; i++)         {             cin >> a[i].ch >> a[i].x >> a[i].y;             vis[a[i].x][a[i].y] = ;         }         ; i < n; i++)         {             ] == 'G')   G(a[i].x, a[i].y);             ] == 'R')   R(a[i].x, a[i].y);             ] == 'C')   C(a[i].x, a[i].y);             ] == 'H')   H(a[i].x, a[i].y);         }         ;         >)         {             ][bs])                 flag = ;         }          < )         {             ][bs])                 flag = ;         }          > )         {             ])                 flag = ;         }          < )         {             ])                 flag = ;         }         )             cout << "NO" << endl;         else             cout << "YES" << endl;         cout << endl;     }     ; }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902