模拟 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]] 的极 ...
随机推荐
- zstu.4194: 字符串匹配(kmp入门题&& 心得)
4194: 字符串匹配 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 206 Solved: 78 Description 给你两个字符串A,B,请 ...
- 教你如何---构建良好的windows程序(初学者必看)
一使用菜单栏和工具栏 1.菜单栏和工具栏有什么作用和优点: 通过菜单栏把应用程序的功能进行分组,能够方便用户查找和使用,下图所示的菜单栏包含的每一项都是顶层菜单项,顶层菜单项下的选项称为”子菜单”或” ...
- MVC中html转义问题(直接输出html的方法)
MVC中如果用@string(string是包含html代码的字符串)形式输出字符串,那么对应的html标签会自动转义,如果想直接输出html可用以下方法: @(new HtmlString( &qu ...
- poj2485 Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- HDOJ 2544
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- C#中Const和Readonly的区别
const 的概念就是一个包含不能修改的值的变量.常数表达式是在编译时可被完全计算的表达式.因此不能从一个变量中提取的值来初始化常量.如果 const int a = b+1;b是一个变量,显然不能再 ...
- 夏令时 DST (Daylight Saving Time) java中的夏令时【转】
1916年,德国首先实行夏令时,英国因为怕德国会从中得到更大的效益,因此紧跟着也采取了夏令时 1986年至1991年,中华人民共和国在全国范围实行了六年夏令时 サマータイム 夏時間(日本现在没有实行夏 ...
- 【转】Oracle数据库中Sequence的用法
在Oracle数据库中,sequence等同于序列号,每次取的时候sequence会自动增加,一般会作用于需要按序列号排序的地方. 1.Create Sequence (注释:你需要有CREATE S ...
- poj_2674 弹性碰撞
题目大意 给定一条直线,长度为L 表示区间[0, L].在直线上开始放置N个人,每个人有一个初始位置pos(用到直线上端点0的距离表示)和初始方向dir('p' 或 'P' 表示向端点L行走, 'n' ...
- object-c学习笔记
原文地址 最近开始学习object-c,分享一下学习oc的经验以及对oc的理解,其中难免会有错误,请大家理解. 对初学者来说,objective-c存在了很多令人费解的写法,当然也包括我! 我刚开始看 ...