【寒假】uva10382 (区间覆盖)
程序员文章站
2023-12-27 10:29:09
...
问题分析:是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));
}
}
推荐阅读
-
【寒假】uva10382 (区间覆盖)
-
BZOJ2298: [HAOI2011]problem a(带权区间覆盖DP)
-
三类贪心区间覆盖问题
-
洛谷P2439 [SDOI2005]阶梯教室设备利用(带权区间覆盖)
-
寒假每日一题day7 AcWing 422. 校门外的树(三种写法的区间合并)线段树写法待补
-
删除被覆盖区间-数组1288-python
-
计蒜客 ICPC焦作网络赛 Modular Production Line(区间k覆盖 + 最小费用最大流)
-
BZOJ2298: [HAOI2011]problem a(带权区间覆盖DP)
-
三类贪心区间覆盖问题
-
洛谷P2439 [SDOI2005]阶梯教室设备利用(带权区间覆盖)