模拟 + 暴搜 --- Help Me with the Game

Help
Me with the Game










Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3175   Accepted: 2053

Description

Your task is to read a picture of a chessboard
position and print it in the chess notation.

Input

The input consists of an ASCII-art picture of a
chessboard with chess pieces on positions described by the input. The pieces of
the white player are shown in upper-case letters, while the black player‘s
pieces are lower-case letters. The letters are one of "K" (King), "Q" (Queen),
"R" (Rook), "B" (Bishop), "N" (Knight), or "P" (Pawn). The chessboard outline is
made of plus ("+"), minus ("-"), and pipe ("|") characters. The black fields are
filled with colons (":"), white fields with dots (".").

Output

The output consists of two lines. The first line
consists of the string "White: ", followed by the description of positions of
the pieces of the white player. The second line consists of the string "Black:
", followed by the description of positions of the pieces of the black player.


The description of the position of the pieces is a comma-separated list
of terms describing the pieces of the appropriate player. The description of a
piece consists of a single upper-case letter that denotes the type of the piece
(except for pawns, for that this identifier is omitted). This letter is
immediatelly followed by the position of the piece in the standard chess
notation -- a lower-case letter between "a" and "h" that determines the column
("a" is the leftmost column in the input) and a single digit between 1 and 8
that determines the row (8 is the first row in the input).

The pieces
in the description must appear in the following order: King("K"), Queens ("Q"),
Rooks ("R"), Bishops ("B"), Knights ("N"), and pawns. Note that the numbers of
pieces may differ from the initial position because of capturing the pieces and
the promotions of pawns. In case two pieces of the same type appear in the
input, the piece with the smaller row number must be described before the other
one if the pieces are white, and the one with the larger row number must be
described first if the pieces are black. If two pieces of the same type appear
in the same row, the one with the smaller column letter must appear first.

Sample Input

+---+---+---+---+---+---+---+---+
|.r.|:::|.b.|:q:|.k.|:::|.n.|:r:|
+---+---+---+---+---+---+---+---+
|:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.|
+---+---+---+---+---+---+---+---+
|...|:::|.n.|:::|...|:::|...|:p:|
+---+---+---+---+---+---+---+---+
|:::|...|:::|...|:::|...|:::|...|
+---+---+---+---+---+---+---+---+
|...|:::|...|:::|.P.|:::|...|:::|
+---+---+---+---+---+---+---+---+
|:P:|...|:::|...|:::|...|:::|...|
+---+---+---+---+---+---+---+---+
|.P.|:::|.P.|:P:|...|:P:|.P.|:P:|
+---+---+---+---+---+---+---+---+
|:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.|
+---+---+---+---+---+---+---+---+

Sample Output

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

【题目来源】

CTU
Open 2005

http://poj.org/problem?id=2996

【题目大意】
读入一张棋盘。白棋用大写字母表示,黑棋用小写字母表示。
其中各个字母的含义:K(国王)、Q(女王)、R(车),B(主教)、N(骑士)、P(兵)。
小写字母a到h表示列,数字1到8表示行。
输出对应的棋子的名称和坐标。注意:兵(P)不用输出名称。

【题目分析】

题目本来很简单,但是如果方法选的不恰当,再简单的题目也会变得很难,所以说做题还是要将大部分的时间花在思考上,而不是写代码上。

这题就是一个简单的模拟+暴搜,没有任何技巧。

思路清晰,就很容易1A。

我看网上有的人写了260多行,狂晕。


#include<cstdio>
char Map[35][35];

void find1(char c)
{
for(int i=1;i<=17;i++)
for(int j=1;j<=33;j++)
{
if(Map[i][j]==c)
{
if(c>=‘A‘&&c<=‘Z‘) printf("%c",c);
else printf("%c",c-32);
printf("%c%d,",‘a‘+j/4,i/2);
}
}
}

void find2(char c)
{
for(int i=17;i>=1;i--)
for(int j=1;j<=33;j++)
{
if(Map[i][j]==c)
{
if(c>=‘A‘&&c<=‘Z‘) printf("%c",c);
else printf("%c",c-32);
printf("%c%d,",‘a‘+j/4,i/2);
}
}
}

void find_write()
{
find1(‘K‘);
find1(‘Q‘);
find1(‘R‘);
find1(‘B‘);
find1(‘N‘);
int flag=0;
for(int i=1;i<=17;i++)
for(int j=1;j<=33;j++)
{
if(Map[i][j]==‘P‘)
{
if(flag)
printf(",%c%d",‘a‘+j/4,i/2);
else printf("%c%d",‘a‘+j/4,i/2);
flag++;
}
}
puts("");
}

void find_black()
{
find2(‘k‘);
find2(‘q‘);
find2(‘r‘);
find2(‘b‘);
find2(‘n‘);
int flag=0;
for(int i=17;i>=1;i--)
for(int j=1;j<=33;j++)
{
if(Map[i][j]==‘p‘)
{
if(flag)
printf(",%c%d",‘a‘+j/4,i/2);
else printf("%c%d",‘a‘+j/4,i/2);
flag++;
}
}
puts("");
}

int main()
{
while(scanf("%s",Map[17]+1)!=EOF)
{
for(int i=16;i>=1;i--)
scanf("%s",Map[i]+1);
printf("White: " );
find_write();
printf("Black: " );
find_black();
}
return 0;
}

模拟 + 暴搜 --- Help Me with the Game

时间: 2024-10-12 06:55:12

模拟 + 暴搜 --- Help Me with the Game的相关文章

HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

Covering Bob's school has a big playground, boys and girls always play games here after school. To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets. Meanwh

子矩阵(暴搜(全排列)+DP)

子矩阵(暴搜(全排列)+DP) 一.题目 子矩阵 时间限制: 1 Sec  内存限制: 128 MB 提交: 1  解决: 1 [提交][状态][讨论版] 题目描述 给出如下定义: 1. 子矩阵:从一个矩阵当中选取某些行和某些列交叉位置所组成的新矩阵(保持行与列的相对顺序)被称为原矩阵的一个子矩阵. 例如,下面左图中选取第2.4行和第2.4.5列交叉位置的元素得到一个2*3的子矩阵如右图所示. 9 3 3 3 9 9 4 8 7 4 1 7 4 6 6 6 8 5 6 9 7 4 5 6 1 的

【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] Description 七夕祭上,Vani牵着cl的手,在明亮的灯光和欢乐的气氛中愉快地穿行.这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是刚刚被精英队伍成员XLk.Poet_shy和lydrainbowcat拯救出来的的applepi.看到两人对太鼓达人产生了兴趣,applepi果断闪

c++20701除法(刘汝佳1、2册第七章,暴搜解决)

20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有满足表达式abcde/fghij=n的abcde和fghij,其中a~j恰好为数字0~9的一个排列. 如果没有符合题意的数,输出0.本题所说的五位数可以包括前导0的,如01234在这里也称为五位数. 输入 一个正整数n  输出 若干行,每行包括两个符合要求的五位正整数(每行的两个数先大后小),两数之

[HDU 5135] Little Zu Chongzhi&#39;s Triangles (dfs暴搜)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 题目大意:给你n条边,选出若干条边,组成若干个三角形,使得面积和最大.输出最大的面积和. 先将边从小到大排序,这样前面的两条边加起来如果不大于第三条边就可以跳出,这是一个存在性条件. dfs(int idx,int now,int cnt,int nowmax)代表我当前处理的是第idx条边,已经加入边集的有cnt条边,当前的边的长度和为now,组成的最大面积和为nowmax. 暴力枚举每个三

HDU 5012 bfs暴搜

Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 243    Accepted Submission(s): 135 Problem Description There are 2 special dices on the table. On each face of the dice, a distinct number wa

HDU 4284 Travel Folyd预处理+dfs暴搜

题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不能访问所以的点,并且获得所以证书. 题解:目标是那些一定要访问的点,怎么到达的我们不关心,但是我们关系花费最少的路径,而且到达那个点后是一定要打工的,如果只是经过,那么在求花费最少的路径的时候已经考虑过了. 因此先用Folyd求出各个点直接的最短路径,由于N很小,又只要求出一个解,所以直接dfs暴搜

bzoj 2241: [SDOI2011]打地鼠(暴搜+减枝)

2241: [SDOI2011]打地鼠 Time Limit: 10 Sec  Memory Limit: 512 MB Submit: 1098  Solved: 691 [Submit][Status][Discuss] Description 打地鼠是这样的一个游戏:地面上有一些地鼠洞,地鼠们会不时从洞里探出头来很短时间后又缩回洞中.玩家的目标是在地鼠伸出头时,用锤子砸其头部,砸到的地鼠越多分数也就越高. 游戏中的锤子每次只能打一只地鼠,如果多只地鼠同时探出头,玩家只能通过多次挥舞锤子的方

Sicily1317-Sudoku-位运算暴搜

最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC之后在那死磕性能... 累积交了45份代码,纪念一下- - 以上展示了从1.25s优化到0.03s的艰苦历程... 来看题目吧,就是一个数独求解的题: 1317. Sudoku Constraints Time Limit: 10 secs, Memory Limit: 32 MB Descript