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

【题意】

【题解】

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. SpringMVC中的 --- 异常处理

    系统异常处理器SimpleMappingExceptionResolver 处理器方法执行过程中,可能会发生异常,不想看到错误黄页,想看到一个友好的错误提示页. 自定义异常处理器 使用异常处理注解

  2. HDU - 3622 Bomb Game(二分+2-SAT)

    题目大意:玩一个放炸弹游戏,有N次放炸弹的机会,每次放炸弹时,你都有两个位置能够选择.问怎样放炸弹,能使爆炸的炸弹的半径的最小值最大(炸弹爆炸半径能够控制,可是爆炸形成的圈不能有重叠部分) 解题思路: ...

  3. C# winform listBox中的项上下移动(转)

    C# winform listBox中的项上下移动 分类: C# winform2009-06-24 12:37 876人阅读 评论(0) 收藏 举报 winformc#object //上移节点   ...

  4. HTML中的文本框textarea标签

    转自:https://www.jb51.net/web/183411.html <textarea></textarea>用来创建一个可以输入多行的文本框,此标志对用于< ...

  5. Hardwood Species(map)

    http://poj.org/problem?id=2418 题意:给定一系列字符串,要求按字典序升序输出每个串,并输出每个串出现的百分比. 用map做的,交c++A了,G++ WA..so sad. ...

  6. linux更换阿里云的源的shell脚本

    #!/bin/bash##########################################Function: update source#Usage: bash update_sour ...

  7. ecshop数据库说明

    数据库 ecshop 表的结构 ecs_account_log 字段 类型 空 默认 含义 log_id mediumint(8) 否 账户记录表 user_id mediumint(8) 否 用户编 ...

  8. 安装robotframework-ride

    先安装好python并配置好环境变量 1.Windows+r后输入CMD 安装robotframework框架 2.输入pip install robotframework 安装RIDE前需要安装的依 ...

  9. JavaScript中变速运动的数学模型构建

    AB两地直线距离相距为S,机器人β从A点向B点行进.已知机器人β的每间隔固定时间行进一段路程,其下次行进的距离为当前距离B点路程的1/q(q为正整数),求机器人第n次行进距离的表达式an以及前n项和公 ...

  10. Aviator

    Aviator 简介¶ Aviator是一个高性能.轻量级的java语言实现的表达式求值引擎,主要用于各种表达式的动态求值.现在已经有很多开源可用的java表达式求值引擎,为什么还需要Avaitor呢 ...