【习题 4-3 UVA - 220】Othello
【链接】 我是链接,点我呀:)
【题意】
【题解】
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的更多相关文章
- UVA 220 Othello
题意:输入n,代表次数,每次输入8*8的棋盘,处理3种命令:①L:打印所有合法操作,②M:放棋子,③Q:打印棋盘然后退出. 思路:①用字符数组存棋盘,整型数组存合法位置. ②查找的方法:当前玩家为cu ...
- [刷题]算法竞赛入门经典(第2版) 4-3/UVa220 - Othello
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa 220 - Othello #include<iostream ...
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- ACM训练计划建议(转)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- 动态规划 Dynamic Programming 学习笔记
文章以 CC-BY-SA 方式共享,此说明高于本站内其他说明. 本文尚未完工,但内容足够丰富,故提前发布. 内容包含大量 \(\LaTeX\) 公式,渲染可能需要一些时间,请耐心等待渲染(约 5s). ...
- UVa第五章STL应用 习题((解题报告))具体!
例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...
- UVa 1600 Patrol Robot (习题 6-5)
传送门: https://uva.onlinejudge.org/external/16/1600.pdf 多状态广搜 网上题解: 给vis数组再加一维状态,表示当前还剩下的能够穿越的墙的次数,每次碰 ...
- 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 ...
- UVa 12100 Printer Queue (习题 5-7)
传送门:https://uva.onlinejudge.org/external/121/12100.pdf 题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), ...
随机推荐
- iOS 9 平台上 AFNetworking 框架 3.0 版本号解决的问题和问题解决
iOS 9 平台上 AFNetworking 框架 3.0 版本号解决的问题和问题解决 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名- ...
- jQuery总结03
1 控制网页元素属性和样式的 jQuery 方法有哪些? 2 利用 jQuery 插入网页节点的方法有哪些? 3 jQuery 中绑定事件是什么,如何解除绑定? 4 jQuery 中的动画效果包括哪些 ...
- Framebuffer 机制【转】
本文转载自:http://blog.csdn.net/paul_liao/article/details/7706477 Framebuffer Framebuffer是Linux系统为显示设备提供的 ...
- Elasticsearch 7.1.1 集群 + 配置身份验证
一.安装Elasticsearch 1.1 环境说明 Centos7.6 Elasticsearch7.1.1 #挂载数据盘 fdisk /dev/vdb n,p,,回车,回车,wq fdisk -l ...
- 【POJ2248、LOJ#10021】 Addition Chains
事先预警:由于我太蒻了,本做法只能在POJ.LOJ等小数据(N<=100)平台上通过,在UVa(洛谷)上大数据并不能通过 戳我获得更好的观看效果 本题不用看,爆搜就是了,但是纯爆搜显然会爆时间, ...
- python请求服务器图片并下载到本地磁盘
>>> import os >>> os.getcwd() 'C:\\Python33' >>> os.chdir('E:\\python\\mm ...
- 反射找Controller中的方法
/// <summary> /// 根据接口编码APICode,调用相应的webapi方法,注意返回值是json字符串 /// </summary> /// <param ...
- 构造函数中this,return的详解
function Foo(name,age){ this.name=name; this.age=age; } var foo=new Foo("Tom",14); foo.nam ...
- ie8及其以下版本兼容性问题之input file隐藏上传文件
文件上传时,默认的file标签很难看,而且每个浏览器下都有很大差距.因此我们基本都把真正的file标签给隐藏,然后创建一个标签来替代它.但是由于IE出于安全方面的考虑上传文件时必须点击file的浏览按 ...
- T-SQL查询高级--理解SQL SERVER中非聚集索引的覆盖,连接,交叉和过滤
写在前面:这是第一篇T-SQL查询高级系列文章.但是T-SQL查询进阶系列还远远没有写完.这个主题放到高级我想是因为这个主题需要一些进阶的知识作为基础..如果文章中有错误的地方请不吝指正.本篇文章 ...