NOIP2012-------跳石头(C语言)
#include<stdio.h> long a[50035]; int check(long mid, long n, long m) { long last, i, ans; last = a[0]; ans = 0; for (i = 1; i <= (n+1); i++) { if (a[i] - last < mid) { ans++; } else { last = a[i]; } } if (ans > m) { return 0; } return 1; } int main() { long l, n, m; scanf("%ld %ld %ld", &l, &n, &m); a[0] = 0; a[n + 1] = l; int i; for (i = 1; i <= n; i++) { scanf("%ld", &a[i]); } long left, right; left = 0; right = l; long mid; while (left <= right) { mid = (left + right) >> 1; if (check(mid, n, m)) { left = mid+1; } else { right = mid-1; } } printf("%ld", left-1); return 0; }