• hihoCoder #1582 : Territorial Dispute 凸包


    #1582 : Territorial Dispute

    时间限制:1000ms
    单点时限:1000ms
    内存限制:256MB

    描述

    In 2333, the C++ Empire and the Java Republic become the most powerful country in the world. They compete with each other in the colonizing the Mars.

    There are n colonies on the Mars, numbered from 1 to n. The i-th colony's location is given by a pair of integers (xi, yi). Notice that latest technology in 2333 finds out that the surface of Mars is a two-dimensional plane, and each colony can be regarded as a point on this plane. Each colony will be allocated to one of the two countries during the Mars Development Summit which will be held in the next month.

    After all colonies are allocated, two countries must decide a border line. The Mars Development Convention of 2048 had declared that: A valid border line of two countries should be a straight line, which makes colonies ofdifferent countries be situated on different sides of the line.

    The evil Python programmer, David, notices that there may exist a plan of allocating colonies, which makes the valid border line do not exist. According to human history, this will cause a territorial dispute, and eventually lead to war.

    David wants to change the colony allocation plan secretly during the Mars Development Summit. Now he needs you to give him a specific plan of allocation which will cause a territorial dispute. He promises that he will give you 1000000007 bitcoins for the plan.

    输入

    The first line of the input is an integer T, the number of the test cases (T ≤ 50).

    For each test case, the first line contains one integer n (1 ≤ n ≤ 100), the number of colonies.

    Then n lines follow. Each line contains two integers xi, yi (0 ≤ xi, yi ≤ 1000), meaning the location of the i-th colony. There are no two colonies share the same location.

    There are no more than 10 test cases with n > 10.

    输出

    For each test case, if there exists a plan of allocation meet David's demand, print "YES" (without quotation) in the first line, and in the next line, print a string consisting of English letters "A" and "B". The i-th character is "A" indicates that the i-th colony was allocated to C++ Empire, and "B" indicates the Java Republic.

    If there are several possible solutions, you could print just one of them.

    If there is no solution, print "NO".

    注意

    This problem is special judged.

    样例输入
    2
    2
    0 0
    0 1
    4
    0 0
    0 1
    1 0
    1 1
    样例输出
    NO
    YES
    ABBA
    平面内给出n个点,有两个人来占领这n个点,问有没有一种占领方式使得用一条直线不能分隔开两个人占领的点。如果有输出占领方式。
    代码:
    //少于3个点一定不能划分,3个点时如果三个点在一条直线上可以划分否则不能划分,大于三个点时求个凸包就行了,如果点全部在凸包
    //上就每隔一个点属于同一个集合,否则图包内的点在一个集合,凸包上的在另一个集合
    //这题用象限的极角排序好像不会对啊还是我写的有问题。。。
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const int INF=0x7fffffff;
    int top,n,q[109],t;
    bool vis[109];
    struct Node { double x,y;int id; }node[109];
    double dis(Node p1,Node p2)
    {
        return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
    }
    double chaji(Node p0,Node p1,Node p2)
    {
        return ((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x));
    }
    bool cmp(Node p1,Node p2)
    {
        double tmp=chaji(node[0],p1,p2);
        if(tmp>0) return 1;
        else if(tmp<0) return 0;
        else return dis(node[0],p1)<dis(node[0],p2);
    }
    void tubao()
    {
        q[0]=0;
        q[1]=1;
        top=1;
        for(int i=2;i<n;i++){
            while(top>0&&chaji(node[q[top-1]],node[q[top]],node[i])<=0)
                top--;
            q[++top]=i;
        }
    }
    int main()
    {
        scanf("%d",&t);
        while(t--){
            int min_i=0;
            scanf("%d",&n);
            for(int i=0;i<n;i++){
                scanf("%lf%lf",&node[i].x,&node[i].y);
                node[i].id=i;
                if(node[min_i].y>node[i].y||(node[min_i].y==node[i].y&&node[min_i].x>node[i].x))
                    min_i=i;
            }
            if(n<=2){
                puts("NO");
                continue;
            }
            swap(node[min_i],node[0]);
            sort(node+1,node+n,cmp);
            tubao();
            if(n==3&&top==2){
                puts("NO");
                continue;
            }
            memset(vis,0,sizeof(vis));
            if(top==n-1) vis[node[q[0]].id]=vis[node[q[2]].id]=1;
            else{
                for(int i=0;i<=top;i++) vis[node[q[i]].id]=1;
            }
            puts("YES");
            for(int i=0;i<n;i++)
                if(vis[i]) printf("A");
                else printf("B");
            printf("
    ");
        }
        return 0;
    }
     
  • 相关阅读:
    Android 开发工具类 06_NetUtils
    Android 开发工具类 05_Logcat 统一管理类
    Android 开发工具类 04_KeyBoardUtils
    Android 开发工具类 03_HttpUtils
    Android 开发工具类 02_DensityUtils
    Android 开发工具类 01_AppUtils
    APP 渠道推广【摘自网络】
    Android SDK 在线更新镜像服务器资源
    使用 Chrome 生成 UUID
    解决div里插入img下边缝隙问题
  • 原文地址:https://www.cnblogs.com/--ZHIYUAN/p/7616905.html
Copyright © 2020-2023  润新知