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

2
1 1 +
2 2 +
2 2 -
1 2 +
2
1 1 +
2 2 +
1 2 +
2 2 -
0

Sample output

Player 2 wins on move 3
Draw

题意:给定一个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);
else
printf("Player 1 wins on move %d\n", bu);
}
else
printf("Draw\n");
}
return 0;
}

UVA 141 The Spot Game 斑点游戏。。的更多相关文章

  1. UVa 340 Master-Mind Hints(猜数字游戏的提示)

    题意  猜数字游戏  统计猜的数字有多少个数字位置正确  有多少个数字在答案中出现可是位置不对  每一个字符仅仅能匹配一次 直接匹配每位数 #include<cstdio> #includ ...

  2. UVA 340 Master-Mind Hints 猜密码游戏(水)

    题意: 给一串密码(第一行),接着再给你很多行猜测,针对每行猜测,输出两个数字,分表代表:同一列上匹配的个数,不同列上匹配的个数.注:匹配指的是一次,一旦配对,不能再与其他配对. 思路: 每接受一行猜 ...

  3. UVA - 1610 Party Games(聚会游戏)(构造)

    题意:输入一个n(2<=n<=1000,n是偶数)个字符串的集合D,找一个长度最短的字符串S(不一定在D中出现),使得D中恰好一半串小于等于S,另一半串大于S.如果有多解,输出字典序最小的 ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  6. 新概念英语三 新东方主讲Lesson1

    新概念二 Lesson95 词汇 ①get a shock 吓了一跳,得到一个惊喜 例:his wife got a shock get into a such mess 这么不幸搞得一片狼籍弄得这样 ...

  7. 09_Sum游戏(UVa 10891 Game of Sum)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P67 例题28: 问题描述:有一个长度为n的整数序列,两个游戏者A和B轮流取数,A先取,每次可以从左端或者右端取一个或多个数,但不能两端 ...

  8. uva 1378 - A Funny Stone Game(组合游戏)

    题目链接:uva 1378 - A Funny Stone Game 题目大意:两个人玩游戏,对于一个序列,轮流操作.每次选中序列中的i,j,k三个位置要求i<j≤k,然后arr[i]减1,对应 ...

  9. uva 1567 - A simple stone game(K倍动态减法游戏)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=4342">题目链接:uva 1567 - ...

随机推荐

  1. 2077 汉诺塔IV

    Problem Description 还记得汉诺塔III吗?他的规则是这样的:不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到小盘的上面.xhd在想 ...

  2. C#命令模式-设计模式学习

    命令模式(Command Pattern) 概述   在软件系统中,“行为请求者”与“行为实现者”通常呈现一种“紧耦合”.但在某些场合,比如要对行为进行“记录.撤销/重做.事务”等处理,这种无法抵御变 ...

  3. Linux下一个C基本的编程----写进Blog在那之前

    展望2周的实习吧. 各种酸甜苦辣.由于公司只是广告.毛承保让我去.严重的歧视.想也想开,争夺.结果让它成为.还是把它写自己的学习经验,我有同样的希望和迷茫的同学.少走一点弯路.行.切入正题: 一.參考 ...

  4. OCP-1Z0-051-名称解析-文章32称号

    32. Which CREATE TABLE statement is valid? A. CREATE TABLE ord_details          (ord_no NUMBER(2) PR ...

  5. WebApi及Fiddler工具

    WebApi及Fiddler工具 1.概述 曾经有人问:asp.net mvc和asp.net webapi区别在哪?这个其实不好回答的.可能因为mvc模式盛行的原因,webapi显得孤芳自赏了,让人 ...

  6. C语言中关键字auto、static、register、const、volatile、extern的作用

    原文:C语言中关键字auto.static.register.const.volatile.extern的作用 关键字auto.static.register.const.volatile.exter ...

  7. WinForm播放视频

    原文:WinForm播放视频 1背景 这几天一老友要求我做个小软件,在WinForm播放视频.印象中微软有个WM控件直接可以使用,晚上研究下 2实现方式 2.1微软草根 最简单的方式,是直接使用微软的 ...

  8. MVC验证08-jQuery异步验证

    原文:MVC验证08-jQuery异步验证 本文主要体验通过jQuery异步验证. 在很多的教材和案例中,MVC验证都是通过提交表单进行的.通过提交表单,可以很容易获得验证出错信息.因为,无论是客户端 ...

  9. ExtJS4 便捷三层开发模式

    ExtJS4 便捷三层开发模式 定义类已经不是ext4.x一个新特性,但与ext3.x的自定义类有语法上的区别.将相关模块封装成类可以有效的减少浏览器的压力,提高渲染速度,同时抽象每一个可重用方法,减 ...

  10. Phpstorm配置phpunit对php进行单元测试

    在 phpstorm 中配置 php 项目的单元测试,项目使用 Composer 进行管理,为了避免在项目中直接引入 phpunit 相关代码包,使项目的 vendor 目录变得臃肿,这里采用全局安装 ...