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 |
代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator