南阳理工OJ_题目710 外星人的供给站

#include <iostream>
#include <stdlib.h>
#include <math.h>
							//贪心算法 
							//把点转换成区间
							//去掉大区间
							//贪心开始... 

using namespace std;

struct seat
{
	int x;			//
	int y;			//坐标 
	double left;	//
	double right;	//区间 
	int flag;		//标记,0为去掉 
};

int cmp(const void *_a, const void *_b);
bool is_in(seat a, double xy, int r);



int main()
{
	int k;
	cin >> k;
	while(k--)
	{
		seat a[110];
		int n, r;
		cin >> n >> r;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i].x >> a[i].y;
			a[i].flag = 1;
			a[i].left = a[i].x - sqrt(r*r - a[i].y*a[i].y);
			a[i].right = a[i].x + sqrt(r*r - a[i].y*a[i].y);
		}
		qsort(a, n, sizeof(seat), cmp);		//按照区间左值排序 
		
		for(int i = 0; i < n; i++)			//去除大区间 
		{
			for(int j = i+1; j < n; j++)
			{
				if(a[i].flag == 1 && a[i].left <= a[j].left && a[i].right >= a[j].right)
					a[i].flag = 0;
			}
		}
		
		int count = 0;
		double current;
		for(int i = 0; i < n; i++)
		{
			if(a[i].flag == 1)
			{
				current = a[i].right;
				count++;
				a[i].flag = 0;
				for(int j = i+1; j < n; j++)
				{
					if(a[j].left <= current && a[j].right >= current)
						a[j].flag = 0;
				}
			}
		}
		cout << count << endl;
	}
}


int cmp(const void *_a, const void *_b)
{
	seat *a;
	seat *b;
	a = (seat *)_a;
	b = (seat *)_b;
	if(a->left > b->left)
		return 1;
	if(a->left == b->left)
		return 0;
	if(a->left < b->left)
		return -1;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值