| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
感谢各位的提示,其实是不用考虑y和d是不是小于0,无解时只用判断y>d就行了,即使d小于0也考虑在内了感谢各位的提示,其实是不用考虑y和d是不是小于0,无解时只用判断y>d就行了,即使d小于0也考虑在内了
刚开始思路完全错了,以为是要先取y值最大的点的x坐标作为雷达坐标,看了贪心的思路后才做出来的。
贴上AC代码:756K 32MS G++
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int n, d, cnt, casecnt = 1;
typedef struct
{
int x, y;
double x1, x2;
} point;
vector<point> islands(1010);
void solve();
int main()
{
// freopen("input", "r", stdin);
ios::sync_with_stdio(false);
while (cin >> n >> d && n != 0) {
islands.resize(n);
for (int i = 0; i < n; i++)
cin >> islands[i].x >> islands[i].y;
solve();
}
// fclose(stdin);
return 0;
}
class cmp
{
public:
bool operator() (const point& lhs, const point& rhs)
{ return lhs.x < rhs.x; }
};
void solve()
{
cnt = 0;
cmp mycmp;
sort(islands.begin(), islands.begin() + n, mycmp);
double nowx = -99999999, x1, x2;
for (int i = 0; i < n; i++) {
if (islands[i].y > d) {
cout << "Case " << casecnt++ << ": -1" << endl;
return ;
}
else {
double tmp = sqrt(d * d - islands[i].y * islands[i].y);
x1 = islands[i].x - tmp;
x2 = islands[i].x + tmp;
if (x1 <= nowx)
nowx = (nowx < x2) ? nowx : x2;
else {
cnt++;
nowx = x2;
}
}
}
cout << "Case " << casecnt++ << ": " << cnt << endl;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator