zoukankan      html  css  js  c++  java
  • 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<bits/stdc++.h>
    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<int> 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() << "
    ";
                for (int i = 0;i < (int)vec.size();i++)
                    cout << vec[i] << ' ';
                cout << "
    ";
                return 0;
            }
            for (int i = 2;i <= n;i++) if (x[i]&1)
                vec.push_back(i);
            if (!vec.empty())
            {
                cout << (int)vec.size() << "
    ";
                for (int i = 0;i < (int)vec.size();i++)
                    cout << vec[i] << ' ' ;
                cout << "
    ";
                return 0;
            }
            for (int i = 1;i <= n;i++)
                x[i]/=2, y[i]/=2;
        }
    }
    
  • 相关阅读:
    第一章 第二节逻辑代数基础
    第一章 第一节数制与编码
    Altium Designer多原理图、PCB更新处理
    AD添加LOGO的方法
    XML中<beans>属性
    程序员值得学习的技术博客
    设计模式
    js分页实例
    Java构造和解析Json数据的方法
    H5+ 移动app学习之三 App离线存储
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12122464.html
Copyright © 2011-2022 走看看