A. Coffee Break

http://codeforces.com/gym/101911/problem/A

题意:要喝n杯咖啡,且要在ai分钟喝,一天长m,每杯要间隔d,下一天间隔默认大于d;问最少喝多少天;

思路:每次二分找出大于等于当前cnt+d位置能喝的ai,如果没有就开新一天; 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))
inline void sc(T &ret)
{
    char c;
    ret = 0;
    while ((c = getchar()) < '0' || c > '9');
    while (c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0'), c = getchar();
    }
}

set s;
mapmp;
int a[maxn];
int main()
{
    int n,m,d;
    cin>>n>>m>>d;
    for(int i=0;i>a[i];
        s.insert(a[i]);
    }
    int cnt=0;
    int ans=1;
    while(s.size()>0)
    {
        set::iterator it=s.lower_bound(cnt);
        if(it==s.end())
        {
            ans++;
            cnt=0;
        }
        else
        {
            mp[*it]=ans;
            s.erase(it);
            cnt=*it+d+1;
        }
    }
    cout<

 

你可能感兴趣的:(二分)