| ||||||||||
| 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 | |||||||||
贴个AC代码,写的不太好,仅供参考#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <sstream>
#include <math.h>
using namespace std;
int main() {
int caseNum = 1;
while (true) {
int n, d;
cin >> n >> d;
if (n == 0 && d == 0)
break;
bool possible = true;
vector<pair<double, double>> ranges;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (y > d) {
possible = false;
}
ranges.push_back(make_pair(x - sqrt((double)(d * d - y * y)), x + sqrt((double)(d * d - y * y))));
}
if (!possible) {
cout << "Case " << caseNum++ << ": " << -1 << endl;
continue;
}
int ans = 1;
sort(ranges.begin(), ranges.end());
double endPoint = ranges[0].second;
for (int i = 1; i < ranges.size(); i++) {
if (ranges[i].first > endPoint) {
ans++;
endPoint = ranges[i].second;
}
else {
endPoint = min(endPoint, ranges[i].second);
}
}
cout << "Case " << caseNum++ << ": " << ans << endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator