Description

There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.

Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.

The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.

Input

The first line contains a single integer — n(1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105).

Output

Output a single integer — the optimal number of visible kangaroos.

Sample Input

Input

8
2
5
7
6
9
8
4
2

Output

5

Input

8
9
1
6
2
6
5
8
3

Output

5

有N个袋鼠每个袋鼠的口袋里可以放一只体重小于其体重的小于它二分之一重量的袋鼠现在将一些袋鼠放进其它的袋鼠口袋里问最多能见到多少袋鼠。

二分法

 #include<cstdio>
#include<algorithm>
using namespace std;
int n,i,a[+],ri,le,mid,ans;
bool f(int x)
{
int i;
for(i = mid ; i < n ; i++)
{
if(a[i]* > a[i-mid])
return ;
}
return ;
}
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(i = ; i < n ; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n,cmp);
le=(n+)/;
ri=n;
while(le <= ri)
{
mid=(le + ri) / ;
if(f(mid))
{
ans=mid;
ri=mid-;
}
else
{
le=mid+;
}
}
printf("%d\n",ans);
}
}

贪心

 #include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int ans,n,i,a[+];
while(scanf("%d",&n)!=EOF)
{
for(i = ; i < n ; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
ans=n;
for(i = n/- ; i >= ; i-- )
{
if(a[i]* <= a[n-])
{
ans--;
n--;
}
}
printf("%d\n",ans);
}
}

Counting Kangaroos is Fun 求最少可见袋鼠数的更多相关文章

  1. pku oj overhang叠加卡片求最少的卡片数

    这个估计是里面第二简单的了,因为第一简单的是求a+b 哈哈,一submit就ac了 题目如下: Description How far can you make a stack of cards ov ...

  2. CodeForces 372 A. Counting Kangaroos is Fun

    题意,有n只袋鼠,没每只袋鼠有个袋子,大小为si,一个袋鼠可以进入另外一个袋鼠的袋子里面,当且仅当另一个袋鼠的袋子是他的二倍或二倍一上,然后中国袋鼠就是不可见的,不能出现多个袋鼠嵌套的情况.让你求最少 ...

  3. HDU 1326 Box of Bricks(水~平均高度求最少移动砖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 题目大意: 给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同. 解题思路: 找到 ...

  4. poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】

    Road Construction Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10141   Accepted: 503 ...

  5. 输入一个数字n 如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数 写出一个函数

    题目: 输入一个数字n  如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数  写出一个函数 首先,这道题肯定可以用动态规划来解, n为整数时,n的解为 n/2 的解加1 n为奇数时 ...

  6. [Leetcode 216]求给定和的数集合 Combination Sum III

    [题目] Find all possible combinations of k numbers that add up to a number n, given that only numbers ...

  7. 我的第一篇博客:不用sizeof求int的bit数

    我的第一篇博客..  还不会什么高端的东西就来点基础的. 不用sizeof求int的bit数 //不用sizeof求int的bit数 #include<stdio.h> int main( ...

  8. hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。

    题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...

  9. java笔试之求最大连续bit数

    功能: 求一个byte数字对应的二进制数字中1的最大连续数,例如3的二进制为00000011,最大连续2个1    输入: 一个byte型的数字    输出: 无     返回: 对应的二进制数字中1 ...

随机推荐

  1. SpringBoot的配置文件加载顺序以及如何获取jar包里的资源路径

    一.读取配置文件的四种方式 这四种配置文件放置方式的读取优先级依次递减,具体可以查看官方文档. 1.1jar包同级目录下的config文件夹里的配置文件 其实我以前就见过这种方式了,只是不知道怎么做的 ...

  2. iOS [CIContext initWithOptions:]: unrecognized selector sent to instance 模拟器 iOS 8.4

    在模拟器(iPhone 4s,iOS 8.4)中运行应用时, 应用crash在了使用CIContext(options:nil) 这个API的一个纯Swift第三方库. StackOverFlow的解 ...

  3. Jquery | 基础 | 慕课网 | 元素选择器

    getElementsByTagName方法得到页面所有的<div>元素 var divs = document.getElementsByTagName('div'); 与 同样的效果, ...

  4. AtCoder Regular Contest 074 F - Lotus Leaves

    题目传送门:https://arc074.contest.atcoder.jp/tasks/arc074_d 题目大意: 给定一个\(H×W\)的网格图,o是可以踩踏的点,.是不可踩踏的点. 现有一人 ...

  5. 后缀数组 DC3构造法 —— 详解

    学习了后缀数组,顺便把DC3算法也看了一下,传说中可以O(n)复杂度求出文本串的height,先比较一下倍增算法和DC3算法好辣. DC3 倍增法 时间复杂度 O(n)(但是常数很大)   O(nlo ...

  6. UVa 1218 Perfect Service 完美的服务

    ***状态设计值得一看dp[u][0]表示u是服务器(以下v均指任意u的子结点,son指u的所有子结点)ap[u][0]=sum{dp[v][1]}+1//错误,服务器是可以和其他服务器相邻的dp[u ...

  7. JAVA常用设计模式(静态化调用和实例化调用的区别,编辑可见 )

    用newInstance()与用new是区别的,区别在于创建对象的方式不一样,前者是使用类加载机制,后者是创建一个新类,且newInstance()只能调用无参构造函数. 最大的区别在于内存.静态方法 ...

  8. PHP fgets 函数

    <?php $handle=fopen("../good/html/1.txt","r"); ; //打开一个远程文件 $content="&q ...

  9. JDBC——入门知识【转】

      1. 什么是JDBC:Java数据库连接性(JavaDatabase Connectivity) API,允许用户从Java应用程序中访问任何表格化数据源. 2. JDBC除了提供到更宽范围的SQ ...

  10. Java基础学习-一切皆为对象

    一切皆为对象 引用 String s; //s是引用,并不是对象. String s = "asdf" //创建一个引用的同时便进行初始化