【习题 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), ...
随机推荐
- everything的使用
https://www.voidtools.com/support/everything/searching/ 打开多个everything进程 https://www.voidtools.com/s ...
- openStack 主机流量计运行状态 随笔记录
root@ruiy-controller:~# ifconfigeth0 Link encap:Ethernet HWaddr 0c:c4:7a:0d:97:2c ine ...
- 75.培训管理-培训信息发布 Extjs 页面
1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...
- PCB Genesis加邮票孔(线与弧)实现算法
一.Genesis加邮票孔(线与弧)实现算法 1.鼠标点击位置P点(可以确认搜索区域位置,确认点击位置周边元素分区,此所讲算法未应用到P点坐标) 2.求出:P1C与P2C (线与弧最近点距离的2个点) ...
- [Apple开发者帐户帮助]二、管理你的团队(1)邀请团队成员
组织可以选择向其开发团队添加其他人员.如果您已加入Apple开发者计划,您将在App Store Connect中管理团队成员.有关详细信息,请转到在App Store Connect帮助中添加用户. ...
- POJ 1118 求平面上最多x点共线
题意:给你n个点的坐标.求一条直线最多能穿过多少个点. 思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成 //By: Sirius_Ren #include <cmath&g ...
- MySQL学习笔记之内连接
不多说,直接上干货! MySQL的内连接 #内连接,两个表按照条件匹配 select class1.stuid,class1.stuname,class1.sex,course from class ...
- Jquery中绑定事件的异同
谈论jquery中bind(),live(),delegate(),on()绑定事件方式 1. Bind() $(selector).bind(event,data,function) Event:必 ...
- c# 官方文档必看
https://docs.microsoft.com/zh-cn/dotnet/csharp/whats-new/csharp-version-history
- CSS的常用属性(二)
盒子模型之边框 border-(top/bottom/left/right)-style: solid 边框的风格 如(solid 实线,dotted 点线,dashed 虚线) border-top ...