【习题 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), ...
随机推荐
- luogu3119 草鉴定
题目大意 给出一个有向图,问将图中的哪一个边翻转,会使节点1所在的强连通分量内的节点数最多.输出这个节点数. 题解 让我们看看暴力怎么做,即枚举每一条边,将其翻转,然后求节点1所在强连通分量节点数,然 ...
- Python 网络爬虫与信息获取(二)—— 页面内容提取
1. 获取超链接 python获取指定网页上所有超链接的方法 links = re.findall(b'"((http|ftp)s?://.*?)"', html) links = ...
- B1588 [HNOI2002]营业额统计 set||平衡树
平衡树题,求每个点的前驱,照例可以用set水过...(平衡树还是不会写) 又新学了一个用法: set <int> ::iterator s1; 这样s1就可以直接附为set中的地址了.但是 ...
- [python基础] Flasky-表单WTForms支持的html字段和内建函数
WTForms 支持的HTML 标准字段如表4-1 所示.表4-1 WTForms支持的HTML标准字段字段类型 说 明StringField 文本字段T ...
- NSURLSession 和 NSURLConnection 的比较
一.NSURLConnection 1.iOS2.0出现,iOS9.0后废弃的网络请求发送方式 2.可以在初始化时确定发送同步还是异步的请求,并且可以选择执行队列. +(void)sendAsynch ...
- GROUPPING和ROLLUP的基本知识
1.GROUPPING 是一个聚合函数,它产生一个附加的列,当用 CUBE 或 ROLLUP 运算符添加行时,附加的列输出值为1,当所添加的行不是由 CUBE 或 ROLLUP 产生时,附加列值为0. ...
- Pie(二分)
http://poj.org/problem?id=3122 题意:将n个圆柱体的不同口味的pie分给m个人,要求每个人分得的pie必须体积相同,且来自于一块pie(即:只分得一种口味的pie),求最 ...
- [Apple开发者帐户帮助]三、创建证书(1)证书概述
在开发应用程序的过程中,您将创建不同的证书类型,以便在不同的上下文中使用.您将为iOS,tvOS和watchOS应用程序使用相同的证书集,并为macOS应用程序使用不同的证书集.您将使用开发证书在设备 ...
- [DP专题]悬线法
参考:https://blog.csdn.net/twtsa/article/details/8120269 先给出题目来源:(洛谷) 1.p1387 最大正方形 2.P1169 棋盘制作 3.p27 ...
- POJ 3630 trie树
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26559 Accepted: 8000 Descripti ...