模拟 POJ 2996 Help Me with the Game
题目地址:http://poj.org/problem?id=2996
/*
题意:给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子
模拟题 + 结构体排序:无算法,switch区分读入的字符,按照黑白的排序规则排序,再输出
注意:(转载)1,棋盘中大写字母表示的是白方棋子,小写是黑方。
2,注意棋盘的行数是从最下面开始计数的。和数组的下标相反。也就是说数组行数为8的棋盘行 数为1(数组从1开始)。
3,最容易忽略也最重要的是:白旗和黑棋在输出的时候其实排序规则是不一样的(但是棋子的类型都要按照KQRBNP顺序)。
主要是行列的优先问题:
白棋先按行数(棋盘的行编号)升序排,然后按照列升序排。解决办法:按行升序扫描输出。
黑棋先按行数(棋盘的编号)降序排,然后按照列升序排。解决办法:按行降序扫描输出。
输出的时候主要是要注意一下循环扫描的顺序就行了。
详细解释:http://poj.org/showmessage?message_id=346814
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
struct NODEb
{
char ch, col;
int pow, row;
}nodeb[];
struct NODEw
{
char ch, col;
int pow, row;
}nodew[];
int a[][];
string s[];
string ss[]; bool cmpw(NODEw x, NODEw y)
{
if (x.pow == y.pow)
{
if (x.row == y.row) return x.col < y.col;
else return x.row < y.row;
}
return x.pow < y.pow;
} bool cmpb(NODEb x, NODEb y)
{
if (x.pow == y.pow)
{
if (x.row == y.row) return x.col < y.col;
else return x.row > y.row;
}
return x.pow < y.pow;
} void work(void)
{
for (int i=; i<=; ++i)
{
int k = ;
for (int j=; j<; j+=)
{
++k;
switch (s[i][j])
{
case 'K': a[i][k] = ; break;
case 'Q': a[i][k] = ; break;
case 'R': a[i][k] = ; break;
case 'B': a[i][k] = ; break;
case 'N': a[i][k] = ; break;
case 'P': a[i][k] = ; break;
case 'k': a[i][k] = -; break;
case 'q': a[i][k] = -; break;
case 'r': a[i][k] = -; break;
case 'b': a[i][k] = -; break;
case 'n': a[i][k] = -; break;
case 'p': a[i][k] = -; break;
case ':': a[i][k] = ; break;
case '.': a[i][k] = ; break;
default: break;
}
}
}
int tb = , tw = ;
for (int i=; i<=; ++i)
{
for (int j=; j<=; ++j)
{
if (a[i][j] > )
{
nodew[++tw].pow = a[i][j];
nodew[tw].row = - i; nodew[tw].col = 'a' + j - ;
switch (a[i][j])
{
case : nodew[tw].ch = 'K'; break;
case : nodew[tw].ch = 'Q'; break;
case : nodew[tw].ch = 'R'; break;
case : nodew[tw].ch = 'B'; break;
case : nodew[tw].ch = 'N'; break;
default: break;
}
}
if (a[i][j] < )
{
nodeb[++tb].pow = -a[i][j];
nodeb[tb].row = - i; nodeb[tb].col = 'a' + j - ;
switch (a[i][j])
{
case -: nodeb[tb].ch = 'K'; break;
case -: nodeb[tb].ch = 'Q'; break;
case -: nodeb[tb].ch = 'R'; break;
case -: nodeb[tb].ch = 'B'; break;
case -: nodeb[tb].ch = 'N'; break;
default: break;
}
}
}
} sort (nodew+, nodew++tw, cmpw);
sort (nodeb+, nodeb++tb, cmpb); cout << "White: ";
for (int i=; i<=tw; ++i)
{
if (nodew[i].pow != )
cout << nodew[i].ch;
cout << nodew[i].col << nodew[i].row;
if (i != tw) cout << ',';
}
cout << endl;
cout << "Black: ";
for (int i=; i<=tb; ++i)
{
if (nodeb[i].pow != )
cout << nodeb[i].ch;
cout << nodeb[i].col << nodeb[i].row;
if (i != tb) cout << ',';
}
cout << endl;
} int main(void) //POJ 2996 Help Me with the Game
{
freopen ("I.in", "r", stdin); for (int i=; i<=; ++i)
{
cin >> ss[i]; cin >> s[i];
}
cin >> ss[]; work (); return ;
} /*
White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
*/
模拟 POJ 2996 Help Me with the Game的更多相关文章
- poj 2996 Help Me with the Game(模拟)
题目:http://poj.org/problem?id=2996 题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按 ...
- POJ 2996 & 2993 国际象棋布局 模拟
Description Your task is to read a picture of a chessboard position and print it in the chess notati ...
- 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0
Help Me with the Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3510 Accepted: ...
- Poj 2996 Help Me with the Game
1.Link: http://poj.org/problem?id=2996 2.Content: Help Me with the Game Time Limit: 1000MS Memory ...
- 模拟 POJ 2993 Emag eht htiw Em Pleh
题目地址:http://poj.org/problem?id=2993 /* 题意:与POJ2996完全相反 模拟题 + 字符串处理:无算法,读入两行字符串找出相应点用used标记,输出时标记过的输出 ...
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- 模拟 POJ 2632 Crashing Robots
题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram
题目传送门 /* 题意:宽度为1,高度不等,求最大矩形面积 stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极 ...
随机推荐
- Crashing Robots(imitate)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8124 Accepted: 3528 D ...
- iOS UILabel圆角
对于UIView 直接设置 uiview.layer.cornerRadius = 5 就可以有圆角了 但是对于UILabel则不然, 要多设置一个uilabel.clipsToBounds = YE ...
- Django 的css和js压缩插件:django_compressor
今天尝试了django_conpressor,一个在django框架中压缩css和js的插件,灰常有用 我把它加载在我的base的HTML template中,原来未经压缩的css和js是: < ...
- 【SpringMVC】SpringMVC系列5之@RequestHeader 映射请求头属性值
5.@RequestHeader 映射请求头属性值 5.1.概述 请求头包含了若干个属性,服务器可据此获知客户端的信息,通过 @RequestHeader 即可将请求头中的属性值绑定到处理方法的入参中 ...
- css 中的度量单位
px 相对长度单位.像素(Pixel). 像素是相对于显示器屏幕分辨率而言的.譬如,WONDOWS的用户所使用的分辨率一般是96像素/英寸.而MAC的用户所使用的分辨率一般是72像素/英寸. em 相 ...
- 7.python模块补充
此文章是对上节文章模块的补充 一,xml模块 xml是实现不同语言或程序之间进行数据交换的协议,可扩展标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言.xml的格式如下 ...
- Servlet、JSP选择题(2)
Java EE软件工程师认证考试 试题库-选择题 一. 选择题(包括单选和双选) 1.B 编写一个Filter,需要( ) A. 继承Filter 类 B. 实现Filter 接口 C. 继承 ...
- Maximum sum(poj 2479)
题意:给一段数列,将这个数列分成两部分,使两部分的最大子段和的和最大,输出和 /* 看数据没想到是(O)n的算法,求出从前向后的最大子段和和从后向前的最大子段和, 然后枚举断点. 第一次提交不小心折在 ...
- java静态与非静态区别
这里的静态,指以static关键字修饰的,包括类,方法,块,字段. 非静态,指没有用static 修饰的. 静态有一些特点: 1.全局唯一,任何一次的修改都是全局性的影响 2.只加载一次,优先于非静态 ...
- hadoop的关键进程
hadoop集群中主要进程有master: NameNode, ResourceManager,slaves: DataNode, NodeManager, RunJar, MRAppMas ...