标签:
/*
贪心WA一发。。二分枚举加的数
赛后发现直接暴力枚举1到1000也是可以的
*/
/************************************************ * Author :Powatr * Created Time :2015-8-30 0:58:45 * File Name :A.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int MAXN = 1e3 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int a[MAXN]; int n; bool check(int x) { int sum = 0; for(int i = 2; i <= n; i++){ if(a[1] + x <= a[i]){ sum += a[i] - a[1] - x + 1; } } if(sum <= x) return true; return false; } int main(){ while(~scanf("%d", &n)){ for(int i = 1; i <= n; i++) scanf("%d", &a[i]); int l = 0, r = 100000; int res = 0; while(l <= r){ int mid = l + r >> 1; if(check(mid)){ r = mid - 1; res = mid; } else l = mid + 1; } printf("%d\n", res); } return 0; }
Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)——A二分——Bear and Elections
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4770914.html