【寒假】uva10382 (区间覆盖)

问题分析:是uva10020的升级,稍微转换下就可以了,坑爹的是题目中说要输入整数,但只有定义成double型才可以通过。。。。。
转换如下图(引用)
在这里插入图片描述
代码:

#include<iostream>
#include<algorithm>
#include<string.h>
#include<cmath>
using namespace std;
struct section
{
	double l;
	double r;
}q[100005];
//int a[100005];
int L, W;
/*void dispose(int a, int b,int &i)
{
	double r = b;
	double loc = a;
	double w = W;
	double temp = sqrt(r*r - 0.25*w*w);
	if (loc - temp >= L || loc + temp <= 0);
	else
	{
		q[i].l = loc - temp;
		q[i++].r = loc + temp;
	}
}*/
int cmp(section a, section b)
{
	return a.l < b.l;
}
int main()
{
	
	int n;
	int s;
	while (scanf("%d%d%d", &n, &L, &W) != EOF)
	{
		double ta, tb;
		int j = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> ta >> tb;
			if (tb*2 <= W)
			{
				continue;
			}
			else
			{
				q[j].l = ta - sqrt(1.0*tb*tb - 0.25*W*W);
				q[j++].r=ta+ sqrt(1.0*tb*tb - 0.25*W*W);
			}
		//	dispose(ta, tb, j);
		}
		sort(q, q + j, cmp);
		if (q[0].l > 0)
		{
			cout << -1 << endl;
			continue;
		}
		
		
			double nr = 0;
			double nl = 0;
			s = 0;
			while (nr < L)
			{
				int flag = 0;
				//int number;
				//nr = nl;
				for (int i = 0; i < j; i++)
				{
					if (nr < q[i].r&&q[i].l <= nl)
					{
						nr = q[i].r;
						//number = i;
						flag = 1;
					}
				}
				if (!flag)
				{
					s = -1;
					break;
				}
				//a[s] = number;
				s++;
				nl = nr;

			}
		cout << s << endl;
		//memset(q, 0, sizeof(q));
	
	}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值