2017广东工业大学程序设计竞赛决赛--Problem B: 占点游戏

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<map>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;

const int INF=1e9+7;
const int maxn=1100;
typedef long long ll;

int t,n;
int xx1,yy1,xx2,yy2;

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        int i,dis=0;
        scanf("%d",&n);
        scanf("%d %d %d %d",&xx1,&yy1,&xx2,&yy2);
        dis=abs(xx1-xx2)+abs(yy1-yy2);
        if((n&1)&&(dis&1)) //先手-追;
        {
            int step=n/2+1;
            if(step>=dis) printf("2\n");
            else printf("1\n");
        }
        else if((n&1)==0&&(dis&1)) //步数为偶数 距离为奇数 先手有利,能够追上 1
        {
            printf("-1\n");
        }
        else if((n&1)&&(dis&1)==0)
        {
            printf("1\n");
        }
        else if((n&1)==0&&(dis&1)==0)
        {
            if(n/2>=dis) printf("1\n");
            else printf("-1\n");
        }
    }
    return 0;
}











posted @ 2017-03-27 16:15  xushukui  阅读(203)  评论(0编辑  收藏  举报