UVA 141 The Spot Game 斑点游戏。。
来源:互联网 发布:怎么在超星数据库撤稿 编辑:程序博客网 时间:2024/06/08 02:11
The Spot Game
The game of Spot is played on an NxN board as shown below for N = 4. During the game, alternate players may either place a black counter (spot) in an empty square or remove one from the board, thus producing a variety of patterns. If a board pattern (or its rotation by 90 degrees or 180 degrees) is repeated during a game, the player producing that pattern loses and the other player wins. The game terminates in a draw after 2N moves if no duplicate pattern is produced before then.
Consider the following patterns:
If the first pattern had been produced earlier, then any of the following three patterns (plus one other not shown) would terminate the game, whereas the last one would not.
Input and Output
Input will consist of a series of games, each consisting of the size of the board, N (2 N 50) followed, on separate lines, by 2N moves, whether they are all necessary or not. Each move will consist of the coordinates of a square (integers in the range 1..N) followed by a blank and a character `+' or `-' indicating the addition or removal of a spot respectively. You may assume that all moves are legal, that is there will never be an attempt to place a spot on an occupied square, nor to remove a non-existent spot. Input will be terminated by a zero (0).
Output will consist of one line for each game indicating which player won and on which move, or that the game ended in a draw.
Sample input
21 1 +2 2 +2 2 -1 2 +21 1 +2 2 +1 2 +2 2 -0
Sample output
Player 2 wins on move 3Draw
题意:给定一个n*n的棋盘, 然后玩家1和玩家2每人轮操作棋子(可以放一个棋子或者拿掉一个棋子)。进行n次。。。然后如果某一个玩家进行一次操作之后。棋盘出现之前出现过的局面,这另外一位玩家获得胜利。。如果放完没人胜利,输出Draw。 注意,棋盘是可以旋转的,看题目中前4副图,代表的都是相同的局面。。
思路:放了棋子的点为1,没放的为0,把每个局面,,保存成一个字符串,,每次放完棋子之后。旋转4次。4种情况都插入到一个set。。如果一个玩家放完棋子后的局面。在set里面可以找到,则这个玩家失败,另一个玩家胜利。。
#include <stdio.h>#include <string.h>#include <iostream>#include <set>using namespace std;int n;int map[55][55];char save[4][2555];int x, y;char c;set<string> adj;void sav(){ memset(save, 0 , sizeof(save)); int t; t = 0; for (int i = 1; i <= n; i ++)for (int j = 1; j <= n; j ++){ save[0][t ++] = map[i][j] + '0';} save[0][t] = '\0'; t = 0; for (int i = 1; i <= n; i ++)for (int j = 1; j <= n; j ++){ save[1][t ++] = map[j][n + 1 - i] + '0';} save[1][t] = '\0'; t = 0; for (int i = 1; i <= n; i ++)for (int j = 1; j <= n; j ++){ save[2][t ++] = map[n + 1 - i][n + 1 - j] + '0';} save[2][t] = '\0'; t = 0; for (int i = 1; i <= n; i ++)for (int j = 1; j <= n; j ++){ save[3][t ++] = map[n + 1 - j][i] + '0';} save[3][t] = '\0';}int main(){ while (~scanf("%d", &n) && n) {int judge = 0;int bu = 0;memset(map, 0 , sizeof(map));adj.clear();for (int i = 0; i < 2 * n; i ++){ scanf("%d%*c%d%*c%c%*c", &x, &y, &c); if (c == '+')map[x][y] = 1; if (c == '-')map[x][y] = 0; sav(); for (int j = 0; j < 4; j ++) {if (adj.find(save[j]) != adj.end()){ judge = 1; break;} } for (int j = 0 ; j < 4; j ++)adj.insert(save[j]); if (judge) {if (bu == 0) bu = i + 1; }}if (judge){ if (bu % 2)printf("Player 2 wins on move %d\n", bu); elseprintf("Player 1 wins on move %d\n", bu);}else printf("Draw\n"); } return 0;}
- UVA 141 The Spot Game 斑点游戏。。
- uva141 - The Spot Game(斑点游戏)
- Uva 141 The spot game
- UVa 141 The Spot Game
- uva 141 - The Spot Game
- uva 141 The Spot Game
- UVa 141 - The Spot Game
- UVA 141 - The Spot Game
- UVA 141 - The Spot Game
- UVa:141 The Spot Game
- UVA 141 - The Spot Game
- UVA - 141 The Spot Game
- UVa 141 - The Spot Game
- uva 141 The Spot Game
- UVA - 141 The Spot Game
- uva 141 The Spot Game hash
- uva 141 The Spot Game(STL set)
- UVa 141 & HOJ 1186 - The Spot Game
- 控制winform文本框输入字符限制(数字或字母、长度)
- GDI对象和CDC的使用方法(防止资源泄漏)
- android启动浏览器
- yaffs chunk was not erased
- 3979 分数加减法
- UVA 141 The Spot Game 斑点游戏。。
- C++数据结构--循环链表的应用--解决约瑟夫问题
- S3C2416 开机运行SD卡程序
- SAX和DOM解析XML区别
- c语言调用约定(x86下的调用栈示意)
- Java字符串转换为日期和时间比较大小
- 在同一个tomcat下,不同的web项目共享session
- asp.net中前台javascript与后台C#交互
- 动态规划 - hdu1501 - poj2192