hdu 1558 并查集+计算几何

易错用 warning标记

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
struct node
{
	double x1,y1,x2,y2;
}p[1005];
int set[1005],num[1005];
bool xiangjiao(int a,int b)
{
	double t1,t2;
	t1 = (p[a].x1 - p[a].x2)*(p[b].y1 - p[a].y2) - (p[b].x1 - p[a].x2)*(p[a].y1 - p[a].y2);
	t1 *= (p[a].x1 - p[a].x2)*(p[b].y2 - p[a].y2) - (p[b].x2 - p[a].x2)*(p[a].y1 - p[a].y2);
	t2 = (p[b].x1 - p[b].x2)*(p[a].y1 - p[b].y2) - (p[a].x1 - p[b].x2)*(p[b].y1 - p[b].y2);
	t2 *= (p[b].x1 - p[b].x2)*(p[a].y2 - p[b].y2) - (p[a].x2 - p[b].x2)*(p[b].y1 - p[b].y2);
	if(t1<=0 && t2<=0) return 1;
	else return 0;
}
int find(int a)
{
	int b = a;
	while(set[a] != a) a= set[a];
	return a;
}
void make(int a,int b)
{
	int c = find(b);
	if(c == a) return;// warning
	num[a] += num[c];
	set[c] = a;
}
int main()
{
//	freopen("t.txt","r",stdin);
	int i,j,t,n,m,id;
	char command;
	scanf("%d",&t);
	while(t--)
	{

		scanf("%d",&n);
		for(i = 0; i < n; i++)// warning
		{
			num[i] = 1;
			set[i] = i;
		}		
		m = 0;
		for(i = 0; i < n; i++)
		{
			command = getchar();
			while(command != 'P' && command != 'Q') command = getchar();
			if(command == 'P')
			{
	-			scanf("%lf%lf%lf%lf",&p[m].x1,&p[m].y1,&p[m].x2,&p[m].y2);
				for(j = 0; j < m; j++)
				{
					if(xiangjiao(m,j))
					{
						make(m,j);
					}
				}
				m++;
			}
			else
			{
				scanf("%d",&id);
				printf("%d\n",num[find(id-1)]); // warning
			}
			
		}
		if(t) printf("\n"); //warning
	}
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值