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

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

【51nod-1432】独木舟的更多相关文章

  1. 51NOD 1432 独木舟(贪心

    1432 独木舟   n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? ...

  2. 51nod 1432 独木舟【贪心】

    1432 独木舟 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两 ...

  3. 51nod 1432 - 独木舟 - [贪心]

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1432 基准时间限制:1 秒 空间限制:131072 KB   ...

  4. 51nod 1432 独木舟

    基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承 ...

  5. 51Nod 1432 独木舟 (贪心)

    n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? Input 第一行包含 ...

  6. 独木舟(51NOD 1432 )

    n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? Input 第一行包含 ...

  7. 51nod——1432 独木桥

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1432 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 ...

  8. 51Nod:独木舟问题(贪心)

    n个人,已知每个人体重,独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? 输入 第一行包含两个正 ...

  9. [51nod] 1432 独木桥 贪心

    n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? Input 第一行包含 ...

  10. 【51NOD】独木舟

    [算法]贪心 [题解]比较经典,用l,r两个定位指针分别从左右向中间推进. #include<cstdio> #include<algorithm> #include<c ...

随机推荐

  1. PHP Web木马扫描器

    <?php  header('content-type:text/html;charset=gbk');  set_time_limit(0);//防止超时  /** * * php目录扫描监控 ...

  2. WEB项目异常处理

    package cn.rest.advice; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger;impor ...

  3. Could not calculate build plan: Plugin org.apache.maven.plugins:maven-war-plugin:2.3

    Maven 导入项目时报错: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-war-plugin:2.3 ...

  4. Ubuntu16.04安装印象笔记

    Nixnote 是一个 Evernote 开源客户端,原名 Nevernote.Evernote 是一个著名的笔记等个人资料整理和同步软件, 因为 Evernote 没有 Linux 下的官方版本,因 ...

  5. 【分库分表】sharding-jdbc—解决的问题

    一.遇到的问题 随着互联网技术和业务规模的发展,单个db的表里数据越来越多,sql的优化已经作用不明显或解决不了问题了,这时系统的瓶颈就是单个db了(或单table数据太大).这时候就涉及到分库分表的 ...

  6. DNSmasq安装配置

    dns安装配置yum -y install dnsmasq dns配置文件vi /etc/dnsmasq.confresolv-file=/etc/resolv.dnsmasq.confaddn-ho ...

  7. 百度开源分布式id生成器uid-generator源码剖析

    百度uid-generator源码 https://github.com/baidu/uid-generator snowflake算法 uid-generator是基于Twitter开源的snowf ...

  8. Redis中RedisTemplate和Redisson管道的使用

    当对Redis进行高频次的命令发送时,由于网络IO的原因,会耗去大量的时间.所以Redis提供了管道技术,就是将命令一次性批量的发送给Redis,从而减少IO. 一.Jedis对redis的管道进行操 ...

  9. 程序员清理xcode垃圾命令

    xcrun simctl list devices xcrun simctl delete unavailable

  10. db2 函数、存储过程示例

    1.函数 --drop function getMaxDate; create FUNCTION getMaxDate (y int, m int ) returns date begin DECLA ...