Divide Points
Problem Description
You are given a set of n ≥ 2 pairwise different points with integer coordinates. Your task is to partition these points into two nonempty groups A and B, such that the following condition holds:
For every two points P and Q, write the Euclidean distance between them on the blackboard: if they belong to the same group — with a yellow pen, and if they belong to different groups — with a blue pen. Then no yellow number is equal to any blue number.
It is guaranteed that such a partition exists for any possible input. If there exist multiple partitions, you are allowed to output any of them.
Input
The first line contains one integer n (2 ≤ n ≤ 103) — the number of points.
The i-th of the next n lines contains two integers xi and yi (−106 ≤ xi ,yi ≤ 106) — the coordinates of the i-th point.
It is guaranteed that all n points are pairwise different.
Output
In the first line, output a (1 ≤ a ≤ n−1) — the number of points in a group A.
In the second line, output a integers — the indexes of points that you include into group A.
If there are multiple answers, print any.
Sample Input
3
0 0
0 1
1 0
Sample Output
1
1
题意
在二维平面内,有n个不同的点,现在需要将这些点分别放在在两个集合内,每个点都应该属于一个集合,每个集合至少有一个点。对于两点间的距离,如果他们属于同一个集合,则用黄色笔写下距离,否则用蓝色笔写下距离,要求没有黄色的数字与蓝色的数字相等。求一种符合要求的构造方法。
题解:
考虑将点的坐标(x,y)分为 x + y x+y x+y为偶数,和 x + y x+y x+y为奇数的情况。对于同一组内,距离的平方一定是偶数,不同组距离的平方一定为奇数。
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctype.h>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<iterator>
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define INF 0x3f3f3f3f
#define eps 1e-6
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1020;
const int mod = 998244353;
int x[maxn], y[maxn], a[maxn];
int main()
{
int n, i, j, k;
scanf("%d", &n);
for(i=1;i<=n;i++)
scanf("%d %d", &x[i], &y[i]);
while(1)
{
int num1 = 0, num2 = 0;
for(i=1;i<=n;i++)
{
if((x[i]+y[i])%2)num1++, a[i] = 1;
else num2++, a[i] = 2;
}
if(num1 != 0 && num2 != 0)
{
printf("%d\n", num1);
for(i=1;i<=n;i++)
if(a[i] == 1)printf("%d ", i);
break;
}
else
{
if(num1 == n)for(i=1;i<=n;i++)x[i]--;
for(i=1;i<=n;i++)
{
int a = (x[i]-y[i]);
int b = (x[i]+y[i]);
x[i] = a/2;
y[i] = b/2;
}
}
}
return 0;
}