码迷,mamicode.com
首页 > 其他好文 > 详细

【51nod-1432】独木舟

时间:2018-07-21 19:19:14      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:return   push   name   bit   else   scanf   分享图片   long   code   

技术分享图片

 

排序后用二分,一直卡在最后一组数据,最后改成long long才AC...

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<LL> a;
int main()
{
    LL n, m, sum = 0, x;
    cin>>n>>m;
    for(LL i=0; i<n; i++)
    {
        scanf("%lld", &x);
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    while(a.size() > 1)
    {
        LL x = a.back();
        LL s = m-x;
        a.erase(a.end()-1);
        LL k = upper_bound(a.begin(), a.end(), s)-a.begin();
        if(a[k-1]<=s)
        {
            a.erase(a.begin()+k-1);
            sum++;
        }
        else
            sum++;
    }
    printf("%lld\n", a.size()==1?sum+1:sum);
    return 0;
}

【51nod-1432】独木舟

标签:return   push   name   bit   else   scanf   分享图片   long   code   

原文地址:https://www.cnblogs.com/lesroad/p/9347613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!