标签:
1 /*
2 二分找到不大于m的最大的数,记做p,只要a[p] + k <= a[p+1]就继续
3 注意:特判一下当没有比m小的数的情况:)
4 */
5 #include <cstdio>
6 #include <cstring>
7 #include <cmath>
8 #include <algorithm>
9 using namespace std;
10
11 typedef long long ll;
12
13 const int MAXN = 1e4 + 10;
14 const int INF = 0x3f3f3f3f;
15 ll a[MAXN];
16
17 int main(void) //2015百度之星初赛1 1001 超级赛亚ACMer
18 {
19 int n, m, k;
20 int t, cas = 0;
21 scanf ("%d", &t);
22 while (t--)
23 {
24 scanf ("%d%d%d", &n, &m, &k);
25 for (int i=1; i<=n; ++i) scanf ("%I64d", &a[i]);
26 sort (a+1, a+1+n);
27
28 int p = lower_bound (a+1, a+1+n, m) - a - 1;
29 // printf ("here %d\n", p);
30 bool flag = true;
31 while (p + 1 <= n && a[p] + k >= a[p+1])
32 {
33 p++;
34 if (k > 0) k--;
35 }
36 if (p < n) flag = false;
37 // printf ("here %d\n", p);
38
39 printf ("Case #%d:\n", ++cas);
40 if (m < a[1]) puts ("madan!");
41 else if (!flag) puts ("madan!");
42 else puts ("why am I so diao?");
43 }
44
45 return 0;
46 }
47
48 /*
49 2
50 5 11 3
51 15 13 10 9 8
52 5 11 3
53 8 9 10 13 16
54 */
二分查找 2015百度之星初赛1 1001 超级赛亚ACMer
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4541588.html