Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个AC代码,写的不太好,仅供参考

Posted by houzhe at 2021-02-19 14:31:10 on Problem 1328
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator