2022 CCPC Weihai--C. Grass

Charles the Rabbit likes eating grass. As the saying goes, rabbits do not eat the grass by their burrows. Therefore, Charles has to go outside his burrow every day to look for grass to eat. One day, Charles comes to a two-dimensional plane with many distinct points. He can choose a point A and another four points B, C, D, E to connect with A to form four segments. We consider these four segments as a clump of grass if they meet the following condition: • Any two of the four segments have only a single point of intersection A between them. For example, in the picture below, (1) is a clump of grass, but (2) is not one as the intersection of segments AC and AE is not only a single point A.

Input

Given n points on a plane, Charles wants to know whether there exists a clump of grass. If so, help him find a certain one. Input The first line contains an integer T (1 ≤ T ≤ 120), indicating the number of test cases. The first line of each test case contains an integer n (1 ≤ n ≤ 25000), indicating the number of points. Each of the following n lines contains two integers x, y (−107 ≤ x, y ≤ 107 ), indicating that the coordinates of the point are (x, y). It is guaranteed that all points are distinct. It is guaranteed that Pn ≤ 105 over all test cases.

Output

For each test case, if there does not exist a clump of grass, output NO in a single line. Otherwise, output YES in the first line. Then output two integers separated by a space in the second line, indicating the coordinates of point A. Then output two integers separated by a space in each of the third to sixth lines, indicating the coordinates of the other four points B, C, D, E. If there is more than one clump of grass, output any.

input

3

5
0 0
1 1
1 -1
-1 1
-1 -1

3
1 1
4 5
1 4

5
1 0
2 0
3 0
4 0
5 0

output

YES
0 0
1 1
1 -1
-1 1
-1 -1
NO
NO

结论:只要存在五个点不全共线,那么一定有解,反之无解。

解析:选点办法就是直接前四个点固定,遍历选取第五个点,如果发现某个点满足条件就枚举每个点是否满足中心点的条件,反之就说明不存在,无解。

中心点条件:枚举该点之后就会产生四条线段,判断这四条线段,看看其它三个点是不是有点在这条线段上,都没有的话就满足条件

#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int N=25010;
long long a[N],b[N];
typedef long long ll;
//判断五点是否共线 
bool pan(ll x1,ll y1,ll x2,ll y2,ll x3,ll y3,ll x4,ll y4,ll x5,ll y5)
{
	if((x2-x1)*(y3-y1)!=(x3-x1)*(y2-y1)) return false;//其中两个斜率不同,肯定就不全共线了
	if((x2-x1)*(y4-y1)!=(x4-x1)*(y2-y1)) return false;
	if((x2-x1)*(y5-y1)!=(x5-x1)*(y2-y1)) return false;
	return true;
}
//判断点3是否在点1和点2线段上
bool on(int x1,int y1,int x2,int y2,int x3,int y3)
 {
     int maxx,minx,maxy,miny;
     maxx = max(x1,x2);
     minx =  min(x1,x2);
     maxy = max(y1,y2);
     miny = min(y1,y2);
     if(!(x3>=minx&&x3<=maxx&&y3>=miny&&y3<=maxy)) return false;//超出线段范围肯定就不在线段上了 
     if((x3-x1)*(y2-y1)==(x2-x1)*(y3-y1)) return true; 
     return false;
 }
void solve()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]);
	if(n<5)
	{
		printf("NO\n");
		return;
	}
	ll x1=a[1],y1=b[1];
	ll x2=a[2],y2=b[2];
	ll x3=a[3],y3=b[3];
	ll x4=a[4],y4=b[4];
	for(int i=5;i<=n;i++)
	{
		ll x5=a[i],y5=b[i];
		if(!pan(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5))
		{
			printf("YES\n");
			ll x[8]={x1,x2,x3,x4,x5};
			ll y[8]={y1,y2,y3,y4,y5};
			for(int j=0;j<5;j++)//枚举中心点
			{
				int f=1;//标记这个点是否能是中心点 
				for(int z=0;z<5;z++)//枚举剩下四个点做线段
				{
					if(z==j) continue;
					for(int p=0;p<5;p++)//枚举剩下三个点看是否在该线段上,是则不符合条件
					{
						if(p==z||p==j) continue;
						if(on(x[j],y[j],x[z],y[z],x[p],y[p]))
						{
							f=0;
							break;
						}
					}
					if(!f) break;
				}
					if(f)
					{
						printf("%lld %lld\n",x[j],y[j]);
						for(int p=0;p<5;p++)
						{
							if(p!=j) printf("%lld %lld\n",x[p],y[p]);
						}
						return;
					}
			}
		}
	}
	printf("NO\n");
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--) solve();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值