模拟 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]] 的极 ...
随机推荐
- CocoStudio基础教程(3)在程序中处理cocoStudio导出动画
1.概述 使用cocoStudio可以方便的制作动画,接下来的工作就是在我们的程序中使用制作的动画.这篇中,我将使用程序将两个动画连接起来 2.关联到项目 运行脚本创建我们的项目,将导出的动画.UI放 ...
- 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(一)
public abstract class Service; [API文档关于Service类的介绍] A Service is an application component representi ...
- 关于Unity3D中Resources动态加载NGUI图片的方法
在NGUI中有些图片我需要动态进行变更或者加载,怎么办? 首先在项目中创建一个Resources目录,接着把需要的图片放在这里面,可以有子文件夹么?当然可以,文件结构很重要哦~ NGUI加载图片的方法 ...
- [codeforces 235]A. LCM Challenge
[codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...
- 查看daemon使用技巧
una ~ # ps -ef|egrep "*d$"或"[a-z]d" //查看现有的服务器上都有哪些服务器进程.root 3509 ...
- 【leetcode】Subsets II
Subsets II Given a collection of integers that might contain duplicates, S, return all possible subs ...
- 利用 FFmpeg palettegen paletteuse 生成接近全色的 gif 动画
下载FFmpeg-VideoToGif-v1.0.bat.7z FFmpeg 2.6 及以上版本有效 未使用palette时 使用palette后 @echo off set inFile=2015. ...
- 【读书笔记】读《JavaScript高级程序设计-第2版》 - 非函数部分
章节列表: 第08章:BOM 第09章:客户端检测 第10章:DOM 第11章:DOM2和DOM3 第12章:事件 第13章:表单脚本 第14章:错误处理与调试 第17章:Ajax和JSON第20章: ...
- BST树
http://www.cnblogs.com/bizhu/archive/2012/08/19/2646328.html 4. 二叉查找树(BST) Technorati 标记: 二叉查找树,BST, ...
- 今天连续几次被其他电脑客户端踢下线,也不知是否是ip冲突
可能是利用ip然后我的网络也没有关掉共享,其次就是远程开启了一个叫做"学生端"的应用,好在我改密码连续两次改的快