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

代码

Posted by jerryjiang at 2011-06-21 23:56:14 on Problem 3258
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>
using namespace std;

int input[50001];

int main() {
	freopen("input","r",stdin);

	int L, N, M;

	cin >> L >> N >> M;

	for (int i = 1; i <= N; i++) {
		scanf("%d", &input[i]);
	}

	input[0] = 0;
	input[N+1] = L;

	sort(input, input + N + 2);

	int low = L, high = L;
	int value;

	for (int i = 1; i <= N + 1; i++) {
		value = input[i] - input[i-1];
		if (value < low) {
			low = value;
		}
	}

	int mid, pre, count;

	while (low < high) {
		count = 0;
		pre = 0;
		mid = low + (high - low) / 2;

		for (int i = 1; i <= N + 1; i++) {
			if (input[i] - input[pre] < mid) { 
				count++;
			} else {
				pre = i;
			}
		}

		if (count <= M) { // Important
			if (low != mid) {
				low = mid;
			} else {
				break;
			}
		} else {
			high = mid;
		}
	}

	cout << low << 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