标签:
2 5 11 3 15 13 10 9 8 5 11 3 8 9 10 13 16
Case #1: why am I so diao? Case #2: madan!Hint第一组样例解释 5个ACMer,初始战斗力选择范围是[0,11],接下来每场战斗力提升上限是3,2,1,0,0,...,0 百小度首先使得自己的初始战斗力为10,打败战斗力为10的第一个ACMer, 然后选择战斗力提升3,变成13,打败战斗力为13的第二个ACMer, 然后选择战斗力提升2,变成15,打败战斗力为15的第三个ACMer, 之后再以任意顺序打败剩下的ACMer
思路:把战斗力从小到大排一下序,从最接近m的数开始寻找,每次二分都是找比m+k最接近的且小于m+k的值,然后知道找到大于最大的值的呢个数为止。
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double eps=1e-10;
const double pi= acos(-1.0);
const int maxn=10010;
LL a[maxn];
int binsearch(int l,int r,LL key)
{
while(l<=r){
int mid=(l+r)>>1;
if(a[mid]==key)
return mid;
else if(a[mid]>key)
r=mid-1;
else if(a[mid]<key)
l=mid+1;
}
return r;
}
int main()
{
int T,i,j;
LL n,m,k;
int icase=1;
int pos,p;
LL key;
scanf("%d",&T);
while(T--){
scanf("%lld %lld %lld",&n,&m,&k);
for(i=1;i<=n;i++)
scanf("%lld",&a[i]);
sort(a+1,a+n+1);
printf("Case #%d:\n",icase++);
pos=0;
key=m;
while(k>=0){
p=binsearch(pos,n,key);
if(p==pos){
printf("madan!\n");
break;
}
else if(p==n){
printf("why am I so diao?\n");
break;
}
key=a[p]+k;
pos=p;
k--;
}
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/u013486414/article/details/46289399