Good Bye 2019 E. Divide Points

链接:

https://codeforces.com/contest/1270/problem/E

题意:

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.

思路:

可以按照xy的和分类,和的奇数偶数都有根据奇偶数分类,否则x和y的两种情况分类。
实现起来也不会。。围观了T神的代码

代码:

#include
using namespace std;
typedef long long LL;

int x[1010], y[1010];
int n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1;i <= n;i++)
        cin >> x[i] >> y[i];
    for (int i = n;i >= 1;i--)
        x[i] -= x[1], y[i] -= y[1];
    while(true)
    {
        vector vec;
        for (int i = 1;i <= n;i++) if ((x[i]+y[i])&1)
            vec.push_back(i);
        if (!vec.empty())
        {
            cout << (int)vec.size() << "\n";
            for (int i = 0;i < (int)vec.size();i++)
                cout << vec[i] << ' ';
            cout << "\n";
            return 0;
        }
        for (int i = 2;i <= n;i++) if (x[i]&1)
            vec.push_back(i);
        if (!vec.empty())
        {
            cout << (int)vec.size() << "\n";
            for (int i = 0;i < (int)vec.size();i++)
                cout << vec[i] << ' ' ;
            cout << "\n";
            return 0;
        }
        for (int i = 1;i <= n;i++)
            x[i]/=2, y[i]/=2;
    }
}

你可能感兴趣的:(Good Bye 2019 E. Divide Points)