【链接】 我是链接,点我呀:)

【题意】

【题解】

legal被我打成leagal...
然后注意输出坐标的时候,格式是%2d..
然后就没啥难的了。。

【代码】

#include <bits/stdc++.h>
using namespace std; const int dx[8]={0,-1,-1,-1,0,1,1,1};
const int dy[8]={-1,-1,0,1,1,1,0,-1}; const int N = 10;
char s[N+10][N+10];
char ope[N+10];
char cur[3]; void _change(){
if (cur[0]=='W')
cur[0] = 'B';
else
cur[0]='W';
} bool ok(int x,int y){
for (int i = 0;i < 8;i++){
int cx = x,cy = y,ok = 0,cntnc = 0;
while (1){
cx+=dx[i],cy+=dy[i];
if (cx>=1 && cx<=8 && cy>=1 && cy<=8){
if (s[cx][cy]=='-') break;
if (s[cx][cy]!=cur[0]) {
cntnc++;
continue;
}
if (cntnc>0) ok = 1;
break;
}else{
break;
}
}
if (ok) return 1;
}
return 0;
} vector<pair<int,int> > getlegalposition(){
vector<pair<int,int> > v;v.clear();
for (int i = 1;i <= 8;i++)
for (int j = 1;j <= 8;j++)
if (s[i][j]=='-' && ok(i,j))
v.push_back({i,j});
return v;
} int main(){
//freopen("/home/ccy/rush.txt","r",stdin);
//freopen("/home/ccy/rush_out.txt","w",stdout);
int T;
cin >> T;
int kase = 0;
while (T--){
if (kase>0) cout<<endl;
kase++;
for (int i = 1;i <= 8;i++) cin >> (s[i]+1);
cin >> cur;
while (cin >> ope){
if (ope[0]=='L'){
vector<pair<int,int> > v = getlegalposition();
if (v.empty()){
cout<<"No legal move."<<endl;
}else{
int cnt = 0;
for (pair<int,int> temp:v){
if (cnt>0) cout<<" ";
cnt++;
cout<<"("<<temp.first<<","<<temp.second<<")";
}
cout<<endl;
}
}
if (ope[0]=='M'){
int x = ope[1]-'0',y= ope[2]-'0';
vector<pair<int,int> > v = getlegalposition();
if (v.empty()) _change(); s[x][y]=cur[0];
int cntb = 0,cntw = 0; for (int i = 0;i < 8;i++){
int cx = x,cy = y,cntnc = 0;
while (1){
cx+=dx[i],cy+=dy[i];
if (cx>=1 && cx<=8 && cy>=1 && cy<=8){
if (s[cx][cy]=='-') break;
if (s[cx][cy]!=cur[0]) {
cntnc++;
continue;
}
if (cntnc>0){
for (int ccx = x,ccy = y;ccx!=cx || ccy!=cy;ccx+=dx[i],ccy+=dy[i]){
s[ccx][ccy] = cur[0];
}
}
break;
}else{
break;
}
}
} _change(); for (int i = 1;i <= 8;i++)
for (int j = 1;j <= 8;j++)
if (s[i][j]=='B')
cntb++;
else if (s[i][j]=='W')
cntw++;
printf("Black - %2d White - %2d\n", cntb, cntw);
}
if (ope[0]=='Q'){
for (int i = 1;i <= 8;i++){
for (int j = 1;j <= 8;j++)
cout<<s[i][j];
cout<<endl;
}
break;
}
}
}
return 0;
}

【习题 4-3 UVA - 220】Othello的更多相关文章

  1. UVA 220 Othello

    题意:输入n,代表次数,每次输入8*8的棋盘,处理3种命令:①L:打印所有合法操作,②M:放棋子,③Q:打印棋盘然后退出. 思路:①用字符数组存棋盘,整型数组存合法位置. ②查找的方法:当前玩家为cu ...

  2. [刷题]算法竞赛入门经典(第2版) 4-3/UVa220 - Othello

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa 220 - Othello #include<iostream ...

  3. ACM训练计划建议(写给本校acmer,欢迎围观和指正)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  4. ACM训练计划建议(转)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  5. 动态规划 Dynamic Programming 学习笔记

    文章以 CC-BY-SA 方式共享,此说明高于本站内其他说明. 本文尚未完工,但内容足够丰富,故提前发布. 内容包含大量 \(\LaTeX\) 公式,渲染可能需要一些时间,请耐心等待渲染(约 5s). ...

  6. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

  7. UVa 1600 Patrol Robot (习题 6-5)

    传送门: https://uva.onlinejudge.org/external/16/1600.pdf 多状态广搜 网上题解: 给vis数组再加一维状态,表示当前还剩下的能够穿越的墙的次数,每次碰 ...

  8. UVa 536 Tree Recovery | GOJ 1077 Post-order (习题 6-3)

    传送门1: https://uva.onlinejudge.org/external/5/536.pdf 传送门2: http://acm.gdufe.edu.cn/Problem/read/id/1 ...

  9. UVa 12100 Printer Queue (习题 5-7)

    传送门:https://uva.onlinejudge.org/external/121/12100.pdf 题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), ...

随机推荐

  1. Java集合类汇总记录--guava篇

    BiMap HashBiMap<K,V> 实现了两份哈希表数据结构(本类独立实现).分别负责两个方向的映射. EnumBiMap<K,V> 两个EnumMap对象分别负责两个方 ...

  2. 查看scn headroom变化趋势的几种方法

    查看scn headroom变化趋势的几种方法 scn headroom问题,本文不做解释. 本文为自己的总结,脚本来自于oracle sr技术project师. 转载请注明出处http://blog ...

  3. @PropertySource&@ImportResource&@Bean

    @**PropertySource**:加载指定的配置文件: ```java /** * 将配置文件中配置的每一个属性的值,映射到这个组件中 * @ConfigurationProperties:告诉 ...

  4. 曼哈顿距离MST

    https://www.cnblogs.com/xzxl/p/7237246.html 讲的不错 /* 曼哈顿距离最小生成树 poj 3241 Object Clustering 按照上面的假设我们先 ...

  5. sublime -text 删除已安装插件

    按ctr+shift +p然后输入remove 回车,再输入要删除的插件名

  6. Shredding Company(dfs)

    http://poj.org/problem?id=1416 题意:将一个数分成几部分,使其分割的各个数的和最大并且小于所给的数. 凌乱了..参考的会神的代码..orz... #include < ...

  7. Cloudera Manager安装之利用parcels方式(在线或离线)安装单节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(Ubuntu14.04)(四)

    .. 欢迎大家,加入我的微信公众号:大数据躺过的坑     免费给分享       同时,大家可以关注我的个人博客:  http://www.cnblogs.com/zlslch/   和  http ...

  8. 将DataTable某一列的值整体赋值给 另一个DataTable

    将 DataTable某一列的值,赋值给 另一个DataTable: DataSet _ds=bll.GetAllList(); //将要取其中一列 DataView view = _ds.Table ...

  9. 2018.10.9 上线发现elasticsearch写入速度超级慢,原来罪魁祸首是阿里云服务的OSS的锅

    问题描述: 按照项目计划,今天上线部署日志系统(收集线上的所有日志,便于问题排查). 运维按照以前的部署过程,部署elasticsearch,部署结束之后,通过x-pack的monitor发现elas ...

  10. supervisord 使用记录

    #supervisor简介 Supervisor是一个 Python 开发的 client/server 系统,可以管理和监控类 UNIX 操作系统上面的进程. #组成部分 supervisord(s ...