首页 练字文章 贪心,错题

贪心,错题

2022-05-16 20:18  浏览数:463  来源:Coat    

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <math.h>
#include<map>
#include<deque>
using namespace std;
struct type
{
double x, y;
bool operator < (const type & w) const
{
return x < w.x;
}
}s[100100];
int main()
{
int n;
double len, w;
while (~scanf("%d%lf%lf", &n, &len, &w))
{
int idx = 0;
double a, b;
for (int i = 0; i < n; i++)
{
cin >> a >> b;
if (b <= (w / 2)) continue;
double dist = sqrt(b * b - (w * w / 4.0));
s[idx].x = a - dist;
s[idx++].y = a + dist;
}
sort(s, s + idx);
double L = 0,R=0;
int res = 0;
bool leap = true;
while (R < len)
{
L = R;
int flag = 0;
for (int i = 0; i < idx; i++)
{
if (s[i].x <= L && s[i].y > R)
{
R = s[i].y;
}
}
if (L == R && L < len)
{
leap = false;
break;
}
res++;
}
if (leap)
cout << res << endl;
else
cout << -1 << endl;
}
}



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)