Description
众所周知的是,TMK特别容易迟到,终于在TMK某次又迟到了之后,Maple怒了,Maple大喊一声:“我要跟你决一死战!”然后Maple就跟TMK玩起了一个关于占点的游戏。
Maple在一个无限展开的只有整数点的二维平面上找到两个点,由TMK和Maple分别操控这两个点,两人轮流操作,每一次操作中TMK或Maple可以把他的点移动一格到上、下、左、右四个方向,当TMK操作时,移动到的这个点会被染成红色,而当Maple操作时,移动到的这个点会被染成蓝色,需要注意的是,两个起始时的两个点也都会被染上相应的颜色,而当任一人走到已经染了不同颜色的点,这个颜色会被覆盖掉,当两个点覆盖在一起时,这个点会被后来的点染色。当游戏结束时染着自己颜色的点就代表被自己占领了。
TMK一下就明白了,这个游戏的目标是让自己占领的点比对方占领的点多,而且要让差值最大。
为了公平一些,Maple决定让TMK来选择先手或后手和让TMK来选择点,相应的Maple就会选择另一个点。
现在给出游戏的总轮数N,Maple选择的两个点的坐标(x1,y1),(x2,y2),要TMK来选择先后手和起始点,假设Maple一定按最优策略来走,问TMK能不能选择先后手和起始点使得自己占领的点比Maple占领的多,如果能,那么同时要求出占领的点数的最大差值。
Input
第一行一个T,代表接下来有T组数据(1<=T<=2000)。
每组数据有五个整数N,x1,y1,x2,y2,代表了操作的总轮数N以及选择的两个起始点(x1,y1),(x2,y2),其中1<=N<=10^8,-10^8<=x1,y1,x2,y2<=10^8,数据保证两个点不相同。
Output
对于每一组数据,如果TMK占领的点不能比Maple占领的多,那么输出-1,否则输出两个占领点数的最大差值。
Sample Input
4
1 0 0 1 0
2 0 0 1 0
1 0 0 2 0
2 0 0 2 0
Sample Output
2
-1
1
-1
好厉害的博弈,我没有看出来
参考博客:点击
看代码
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<time.h>
#include<iostream>
#define lowbit(x) (x&-x)
#define abs(x) ((x)>0?(x):-(x))
using namespace std;
typedef long long ll;
const double Pi = acos(-1.0);
const int N = 1e6+10, M = 1e3+20, mod = 1e9+7, inf = 2e9+10;
const double e=2.718281828459 ;
const double esp=1e-9;
int main()
{
int t,n,x1,y1,x2,y2;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d%d",&n,&x1,&y1,&x2,&y2);
int dis=abs(x1-x2)+abs(y1-y2);
if((n+1)/2>=dis) //哈顿满距离能走到
{
if(dis&1) //如果距离奇数
{
if(n&1) puts("2");
else puts("-1");
}
else
{
// if(n&1)
puts("1"); //这里应该都是先者
// else puts("-1");
}
}
else
{
if(n&1) puts("1");
else puts("-1");
}
}
return 0;
}