POJ 1021 2D-Nim
Description
The player on move may remove (A), (B), (A, B), (A, B, C), or (B,F), etc., but may not remove (A, C), (D, E), (H, I) or (B, G).
For purposes of writing 2D-Nim-playing software, a certain programmer wants to be able to tell whether or not a certain position has ever been analyzed previously. Because of the rules of 2D-Nim, it should be clear that the two boards above are essentially equivalent. That is, if there is a winning strategy for the left board, the same one must apply to the right board. The fact that the contiguous groups of pieces appear in different places and orientations is clearly irrelevant. All that matters is that the same clusters of pieces (a cluster being a set of contiguous pieces that can be reached from each other by a sequence of one-square vertical or horizontal moves) appear in each. For example, the cluster of pieces (A, B, C, F, G) appears on both boards, but it has been reflected (swapping left and right), rotated, and moved. Your task is to determine whether two given board states are equivalent in this sense or not.
Input
Output
Sample Input
2
8 5 11
0 0 1 0 2 0 5 0 7 0 1 1 2 1 5 1 3 3 5 2 4 4
0 4 0 3 0 2 1 1 1 4 1 3 3 3 5 2 6 2 7 2 7 4
8 5 11
0 0 1 0 2 0 5 0 7 0 1 1 2 1 5 1 3 3 6 1 4 4
0 4 0 3 0 2 1 1 1 4 1 3 3 3 5 2 6 2 7 2 7 4
Sample Output
YES
NO
Source
#include <iostream> using namespace std; bool map[][];
int W, H, n; struct dot
{
int x, y;
}dots[]; int dot1[], dot2[]; void quicksort(int left, int right, int *dotx)
{
int i, j, temp;
if (left < right)
{
i = left, j = right, temp = dotx[left];
while (i < j)
{
while (i < j&&dotx[j] >= temp) j--;
dotx[i] = dotx[j];
while (i < j&&dotx[i] <= temp) i++;
dotx[j] = dotx[i];
}
dotx[i] = temp;
quicksort(left, j - , dotx);
quicksort(j + , right, dotx);
}
} void Count(int *dot, int i)
{
int x, y, sum;
sum = ;
x = dots[i].x;
y = dots[i].y;
y--;
while (map[x][y] && y >= ) //统计左边点的个数
{
sum++;
y--;
}
y = dots[i].y;
y++;
while (map[x][y] && y < H) //统计右边点的个数
{
sum++;
y++;
}
y = dots[i].y;
x--;
while (map[x][y] && x >= ) //统计下面点的个数
{
sum++;
x--;
}
x = dots[i].x;
x++;
while (map[x][y] && x < W) //统计上面点的个数
{
sum++;
x++;
}
dot[i] = sum;
} int main()
{
int t;
cin >> t;
int sum1, sum2;
while (t--)
{
sum1 = sum2 = ;
memset(map, false, sizeof(map));
cin >> W >> H >> n;
for (int i = ; i <= n; i++) //输入第一组点
{
cin >> dots[i].x >> dots[i].y;
map[dots[i].x][dots[i].y] = true;
}
for (int i = ; i <= n; i++)
Count(dot1, i), sum1 += dot1[i]; //第一张图的连续点数
memset(map, false, sizeof(map));
for (int i = ; i <= n; i++) //输入第二组点
{
cin >> dots[i].x >> dots[i].y;
map[dots[i].x][dots[i].y] = true;
}
for (int i = ; i <= n; i++)
Count(dot2, i), sum2 += dot2[i]; //第二张图的连续点数
if (sum1 != sum2) cout << "NO" << endl;
else
{
quicksort(, n, dot1);
quicksort(, n, dot2);
int flag = ;
for (int i = ; i <= n; i++)
{
if (dot1[i] != dot2[i])
{
//我之前在这里写了输出用来看数据的
//我提交的时候忘记删了,结果还对了
//不得不说这测试数据是真的水
flag = ;
break;
}
}
if (flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
}
POJ 1021 2D-Nim的更多相关文章
- Georgia and Bob POJ - 1704 阶梯Nim
$ \color{#0066ff}{ 题目描述 }$ Georgia and Bob decide to play a self-invented game. They draw a row of g ...
- poj 1021矩阵平移装换后是否为同一个矩阵
2D-Nim Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3081 Accepted: 1398 Descriptio ...
- POJ 1704 Staircase Nim 阶梯博弈
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ...
- POJ 1021 人品题
报告见代码.. #include <iostream> #include <cstdio> #include <cstring> #include <algo ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
- 狗狗40题~ (Volume C)
A - Triangles 记忆化搜索呗.搜索以某三角形为顶的最大面积,注意边界情况. #include <stdio.h> #include <cstring> #inclu ...
- 【POJ】【2068】Nim
博弈论/DP 这是Nim?这不是巴什博奕的变形吗…… 我也不会捉啊,不过一看最多只有20个人,每人最多拿16个石子,总共只有8196-1个石子,范围好像挺小的,嗯目测暴力可做. so,记忆化搜索直接水 ...
- 【POJ】【2975】Nim
博弈论 我哭……思路错误WA了6次?(好像还有手抖点错……) 本题是要求Nim游戏的第一步必胜策略有几种. 一开始我想:先全部异或起来得到ans,从每个比ans大的堆里取走ans个即可,答案如此累计… ...
- POJ 1704 Georgia and Bob (Nim游戏变形)
题目:http://poj.org/problem?id=1704 思路:Nim游戏策略,做如下转换,如果N是偶数,则两两配对,将两个数之间的格子数(距离)看做成这一堆石头的数量. 如果N是奇数,则将 ...
随机推荐
- thinkphp开发微信公众号时,验证基本配置提示请求url超时
原因在index.php入口文件中必须有define('APP_NAME', 'Weixin'); 服务器url:http://bxu2713700584.my3w.com/Weixin/Index/ ...
- 从#65279字符看dede模板页面编码问题
今天一位朋友让帮忙给解决一个dede模板的问题,问题主要是:模板文件生成html文件之后会在body开头处加入一个可见的控制符,导致页面头部会出现一个空白行. 接到"& ...
- Shell中$X的含义
$0 表示这个程序的执行名字,包含输入参数$n 表示这个程序的第n个参数值$* 表示这个程序的所有参数,此选项参数可超过9个.$# 表示这个程序的参数个数$$ 表示这个程序的PID(脚本运行的当 ...
- spring boot项目编译出来的jar包如何更改端口号
执行的时候更改端口即可 . java -Dserver.port=9999 -jar boot.jar
- gRPC实战
gRPC是Google开源的一款非常棒的系统间通信工具,完美的communication抽象,构建在protobuf之上的RPC. 下面我们聊聊它的应用场景,grpc为分布式系统而生,可以是系统间通信 ...
- mysql中能够使用索引的典型场景
mysql 演示数据库:http://downloads.mysql.com/docs/sakila-db.zip 匹配全值 explain select * from rental where re ...
- RocketMQ环境搭建(双master双slave模式)
1.环境准备: 准备四台主机(我这里用CentOSx64) 主机 角色 broker 192.168.192.130 Master1 BrokerServerA 192.168.192.131 Mas ...
- Django_注册全局消息
需求: 对于登录用户,无论他在哪个页面,我都需要给他全局发送一个消息提示,Django中request就是一个全局变量 那,如何做? 在models 中urser表,继承user的表类中写上一个函数, ...
- duilib消息类型
//定义所有消息类型 ////////////////////////////////////////////////////////////////////////// #define DUI_MS ...
- 【转】rinex
RINEX(Receiver INdependent Exchange)格式是与接收机无关的数据交换格式,该格式采用文本文件存储数据,数据记录格式与接收机的制造厂商和具体型号无关.RINEX ...