博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hihoCoder #1582 : Territorial Dispute 凸包
阅读量:4656 次
发布时间:2019-06-09

本文共 3828 字,大约阅读时间需要 12 分钟。

#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.

样例输入
220 00 140 00 11 01 1
样例输出
NOYESABBA
平面内给出n个点,有两个人来占领这n个点,问有没有一种占领方式使得用一条直线不能分隔开两个人占领的点。如果有输出占领方式。
代码:
//少于3个点一定不能划分,3个点时如果三个点在一条直线上可以划分否则不能划分,大于三个点时求个凸包就行了,如果点全部在凸包//上就每隔一个点属于同一个集合,否则图包内的点在一个集合,凸包上的在另一个集合//这题用象限的极角排序好像不会对啊还是我写的有问题。。。#include
#include
#include
#include
#include
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)
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
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

 

 

转载于:https://www.cnblogs.com/--ZHIYUAN/p/7616905.html

你可能感兴趣的文章
泛型在三层中的应用
查看>>
SharePoint2010 -- 管理配置文件同步
查看>>
.Net MVC3中取得当前区域的名字(Area name)
查看>>
获得屏幕像素以及像素密度
查看>>
int与string转换
查看>>
adb命令 判断锁屏
查看>>
推荐一个MacOS苹果电脑系统解压缩软件
查看>>
1035等差数列末项计算
查看>>
CDMA鉴权
查看>>
ASP.NET MVC Identity 兩個多個連接字符串問題解決一例
查看>>
过滤器与拦截器区别
查看>>
第二阶段站立会议7
查看>>
JAVA多线程
查看>>
delphi 更改DBGrid 颜色技巧
查看>>
POJ 2031 Building a Space Station
查看>>
任意阶幻方(魔方矩阵)C语言实现
查看>>
织梦教程
查看>>
杭电多校 Harvest of Apples 莫队
查看>>
C/C++心得-结构体
查看>>
函数名作为参数传递
查看>>