hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

#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

题目链接:

  http://hihocoder.com/problemset/problem/1582

题目大意:

  一个二维平面,上面有一些点,问是否存在01染色方案,使得0和1的点无法被一条直线区分开。

题目思路:

  【凸包】

  一开始题目看错了以为是沿着网格的边的折线。。

  首先可以知道n>3时只要满足存在两条线段,一条以2个0为端点,一条以2个1为端点,这两条线段相交即可

  n=3时三角形无解,共线时中间的点为0,端点为1即可。

  n=2或者1时无解。

  可以求个凸包,然后判断,如果有节点不在凸包上,那么必有解,将不在凸包的点染为1,在的为0,即可。

  如果节点全在凸包上,若n>3,则取不相邻的两个节点染为1,其余为0即可。否则无解。




/****************************************************

	Author : Coolxxx
	Copyright 2017 by Coolxxx. All rights reserved.
	BLOG : http://blog.csdn.net/u010568270

****************************************************/
#include<bits/stdc++.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define mem(a,b) memset(a,b,sizeof(a))
const double EPS=0.00001;
const int J=10;
const int MOD=1000000007;
const int MAX=0x7f7f7f7f;
const double PI=3.14159265358979323;
const int N=104;
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
bool mark[N];
class xxx
{
public:
	int x,y,num;
	xxx(){}
	xxx(int x,int y)
	{
		this->x=x;
		this->y=y;
	}
	int dis()
	{
		return sqr(x)+sqr(y);
	}
	int dis(xxx aa)
	{
		return sqr(x-aa.x)+sqr(y-aa.y);
	}
	xxx operator - (const xxx &bb)
	{
		return xxx(this->x-bb.x,this->y-bb.y);
	}
}a[N],s[N];
int Cross(xxx aa,xxx bb)
{
	return aa.x*bb.y-aa.y*bb.x;
}
int Cross(xxx aa,xxx bb,xxx cc)
{
	return Cross(bb-aa,cc-aa);
}
bool cmp1(xxx aa,xxx bb)
{
	return aa.y!=bb.y?aa.y<bb.y:aa.x<bb.x;
}
bool cmp(xxx aa,xxx bb)
{
	return Cross(a[1],aa,bb)!=0?(Cross(a[1],aa,bb)>0):(aa.dis(a[1])<bb.dis(a[1]));
}
bool judge()
{
	int i;
	if(lll<n)
	{
		for(i=1;i<=lll;i++)
			mark[s[i].num]=1;
		return 1;
	}
	else if(n>3)
	{
		mark[s[1].num]=mark[s[3].num]=1;
		return 1;
	}
	else return 0;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("1.txt","r",stdin);
//	freopen("2.txt","w",stdout);
	#endif
	int i,j,k;
	int x,y,z;
	for(scanf("%d",&cass);cass;cass--)
//	init();
//	for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
//	while(~scanf("%d",&n))
	{
		mem(mark,0);lll=0;
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&a[i].x,&a[i].y);
			a[i].num=i;
		}
		sort(a+1,a+1+n,cmp1);
		sort(a+2,a+1+n,cmp);
		for(i=1;i<=n;i++)
		{
			while(lll>1 && Cross(s[lll-1],a[i],s[lll])>=0)
				lll--;
			s[++lll]=a[i];
		}
		
		for(i=1;i<=lll;i++)s[i+lll]=s[i];
		for(i=2,j=1;i<=lll;i++)
			if(s[i].num<s[j].num)j=i;
		for(i=j;i<j+lll;i++)
			printf("%d ",s[i].num);
		puts("");
		
		if(judge())
		{
			puts("YES");
			for(i=1;i<=n;i++)
				printf("%c",mark[i]?'A':'B');
			puts("");
		}
		else puts("NO");
	}
	return 0;
}
/*
//

//
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
territorial emissions是指一个国家或地区在本地境内产生的温室气体排放量。这包括工业生产、交通运输、能源生产和消费等各个领域所产生的二氧化碳、甲烷、氮氧化物等温室气体排放。对于一个国家来说,控制和减少本地的territorial emissions是减少全球气候变化影响的重要途径之一。 随着全球气候变化问题的不断加剧,越来越多的国家和地区开始重视控制自身的territorial emissions。为了实现这一目标,一些国家采取了一系列政策和措施,包括加强对工业和交通排放的管控、推动清洁能源和可再生能源的发展、鼓励节能减排和减少资源消耗等方面的举措。通过这些努力,一些国家已经取得了一些成效,减少了一定比例的温室气体排放。 然而,要实现全球温室气体排放的减少,单靠控制territorial emissions还远远不够。因为地球上的大气是一个共同的资源,一个国家的排放减少不意味着其对全球气候变化问题的贡献就达到了最优。因此,全球各国需要加强合作,共同努力,制定更加严格的减排目标和措施,从而共同应对全球气候变化挑战。 总之,territorial emissions是指一个国家本土所产生的温室气体排放量,在应对全球气候变化问题的过程中,控制和减少territorial emissions是至关重要的一环。同时,国际合作也是必不可少的,只有全球各国共同努力,才能真正应对气候变化挑战。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值