51nod-1420-贪心
有n只袋鼠。每只袋鼠的大小用一个整数表示。一只小袋鼠能装进一只大袋鼠的条件是,大袋鼠的大小至少是小袋鼠的两倍。
每只大袋鼠最多可以装一只袋鼠。小袋鼠被装进大袋鼠之后就不能再装其它的袋鼠了。
小袋鼠被装进大袋鼠之后就不能被我们看见了。请找出一个装袋鼠的方案,使得被看见的袋鼠最少。
单组测试数据。
第一行包含一个整数n(1≤n≤5*10^5)。
接下来n行,每行一个整数si,表示第i只袋鼠的大小 (1≤si≤10^5)。
输出一个整数,即最少能看见的袋鼠数量。
8
2
5
7
6
9
8
4
2
5 最少能看见(n+1)/2的袋鼠,因为每只袋鼠最多装一只袋鼠。所以排序后考虑用后半部分装前半部分,贪心的考虑,我们应该用大袋鼠装尽可能大的小袋鼠,如果装不下,说明没有更大的能装下,略过即可。
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<stack>
#include<set>
#include<cmath>
#include<ctime>
#include<time.h>
#include<algorithm>
using namespace std;
#define mp make_pair
#define debug puts("debug")
#define LL long long
#define pii pair<int,int>
vector<LL>a;
bool vis[];
int main(){
LL n,i,j,k;
cin>>n;
for(i=;i<=n;++i){
scanf("%lld",&k);
a.push_back(k);
}
sort(a.begin(),a.end());
for(i=n/-;i>=;--i){
if(a[i]*<=a[n-]){
n--;
}
}
cout<<n<<endl;
return ;
}
51nod-1420-贪心的更多相关文章
- 51nod - 1420 - 数袋鼠好有趣 - 贪心 - 二分
https://www.51nod.com/Challenge/Problem.html#!#problemId=1420 一开始乱搞了一发,每个袋鼠二分找最小的能放它的,然后二分的范围从下一个开始保 ...
- 51nod 1420 数袋鼠好有趣【贪心】
1420 数袋鼠好有趣 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 有n只袋鼠.每只袋鼠的大小用一个整数表示. ...
- 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 ...
随机推荐
- c# 网站 vislual studio
一.新建 1.新建网站 在 菜单栏-->新建-->项目-->选项编辑语言-->web-->先前版本-> 2.新建母板: *.master文件是母板页文件.添加新项时 ...
- This module embeds Lua, via LuaJIT 2.0/2.1, into Nginx and by leveraging Nginx's subrequests, allows the integration of the powerful Lua threads (Lua coroutines) into the Nginx event model.
openresty/lua-nginx-module: Embed the Power of Lua into NGINX HTTP servers https://github.com/openre ...
- 省市县三级联动的SQL
完整版见https://jadyer.github.io/ 首先是建表语句 CREATE TABLE `t_address_province` ( `id` INT AUTO_INCREMENT PR ...
- 2014年百度之星程序设计大赛 - 资格赛 1001 Energy Conversion
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/sr19930829/article/details/26003661 Energy Conversi ...
- PAT 1053 Path of Equal Weight[比较]
1053 Path of Equal Weight(30 分) Given a non-empty tree with root R, and with weight Wi assigned t ...
- Django 基础篇章
Django 紧紧地遵循这种 MVC 模式,可以称得上是一种 MVC 框架. 以下是 Django 中 M.V 和 C 各自的含义: M ,数据存取部分,由django数据库层处理. V ,选择显示哪 ...
- 5.6 Components -- Handling User Interaction with Actions
1. 组件允许你定义可以在整个应用程序中重用的控件.如果它们够通用,它们也可以在被共享给其他人并且在许多应用程序中被使用. 2. 为了使一个可重用的控件有用,然而,你首先需要你的应用程序的用户和它交互 ...
- addslashes — 使用反斜线引用字符串
返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线.这些字符是单引号(').双引号(").反斜线(\)与 NUL( NULL 字符). 一个使用 addslashes() ...
- [转]Birdfont 2.10 发布,字体编辑器
最近在忙大数据.黑天鹅算法实盘测试 许久没有更新字库方面的资料,汗一个... 今天转一个 :Birdfont 2.10 发布,字体编辑器 字体编辑器,向来很少,除了fontlab的几个昂贵的商业版,就 ...
- Python:导入numpy报错 No module named numpy
Numpy是python的一种开源的数值计算扩展.这种工具可用来存储和处理大型矩阵,比python自身的嵌套列表结构要高效的多.但是在使用numpy时可能会出错(如上图). 解决办法:下载安装对应版本 ...