51Nod 独木舟(贪心)
n个人,已知每个人体重。独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人。显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟?
第一行包含两个正整数n (0<n<=10000)和m (0<m<=2000000000),表示人数和独木舟的承重。
接下来n行,每行一个正整数,表示每个人的体重。体重不超过1000000000,并且每个人的体重不超过m。
一行一个整数表示最少需要的独木舟数。
3 6
1
2
3
2
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
typedef long long ll;
int n,m;
int a[];
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int l=,r=n-;
int ans=;
while(l<=r)
{
if(a[l]+a[r]<=m) l++;
r--;
ans++;
}
printf("%d\n",ans);
return ;
}
51Nod 独木舟(贪心)的更多相关文章
- 51nod 1432 - 独木舟 - [贪心]
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1432 基准时间限制:1 秒 空间限制:131072 KB ...
- 51nod 1163贪心
用优先队列来贪心,是一个很好地想法.优先队列在很多时候可以维护最值,同时可以考虑到一些其他情况. http://www.51nod.com/onlineJudge/questionCode.html# ...
- 51nod 1625 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 1625 夹克爷发红包 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1099 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 1099 任务执行顺序 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1428 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1672 贪心/队列
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...
- 51nod 1449 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1449 1449 砝码称重 题目来源: CodeForces 基准时间限制 ...
- 51nod 1255 贪心/构造
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1255 1255 字典序最小的子序列 题目来源: 天津大学OJ 基准时间限 ...
- 51nod 1163 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励 基准时间限制:1 秒 空间限制:131072 ...
随机推荐
- iptables 防火墙 只允许某IP访问某端口、访问特定网站
iptables 防火墙 只允许某IP访问某端口.访问特定网站 1.先备份iptables /var/tmp 需要开80端口,指定IP和局域网 下面三行的意思: 先关闭所有的80端口 开启ip段192 ...
- vue中router-link的click事件失效的解决办法
title: vue中router-link的click事件失效的解决办法 toc: false date: 2018-12-04 16:28:49 categories: Web tags: vue ...
- luogu 2869 挑剔的美食家
Gourmet Grazers 传送门 题目大意 约翰的奶牛对食物越来越挑剔了.现在,商店有\(M\) 份牧草可供出售,奶牛食量很大,每份牧草仅能供一头奶牛食用.第\(i\) 份牧草的价格为\(P_i ...
- IDEA模板设置
/** * @className: $CLASSNAME$ * @author: liuyachao * @date: $DATE$ $TIME$ */ ================= ...
- Idea怎么添加类的注释模板
Idea添加类的注释模板: File-->Settings-->Live Templates-->点击+号按钮添加模板 添加自定义分组名,添加自定义模板名,如图所示add,添加完成后 ...
- swift语言点评十-Value and Reference Types
结论:value是拷贝,Reference是引用 Value and Reference Types Types in Swift fall into one of two categories: f ...
- Django——Model
一. ORM 在 MVC 或者说 MTV 设计模式中,模型(M)代表对数据库的操作.那么如何操作数据库呢? 我们可以在 Python 代码中嵌入 SQL 语句. 但是问题又来了,Python 怎么连接 ...
- 路飞学城Python-Day10
[37.函数-命名空间]命名空间又称为name space,顾名思义就是存放名字的地方,存什么名字呢?举例说明,若变量 x = 1,存放于内存中,那名字x存放在哪里呢?名称空间正式存放名字x和1绑定关 ...
- [转载]PyCharm创建.py自动添加文件头注释
转自:https://blog.csdn.net/qq_36482772/article/details/67218214 创建.py文件时 顺便自动添加作者.时间.文件名信息…… mac系统打开编辑 ...
- BZOJ 2287 【POJ Challenge】消失之物(DP+容斥)
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 986 Solved: 572[Submit][S ...