首頁 文章 贪心,错题

贪心,错题

2022-05-16 20:18  瀏覽數:506  來源: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)