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. Apache-kylin-2.0.0-bin-hbase1x.tar.gz的下载与安装(图文详解)

    首先,对于Apache Kylin的安装,我有话要说. 由于Apache Kylin本身只是一个Server,所以安装部署还是比较简单的.但是它的前提要求是Hadoop.Hive.HBase必须已经安 ...

  2. CDH版本大数据集群下搭建的Hue详细启动步骤(图文详解)

    关于安装请见 CDH版本大数据集群下搭建Hue(hadoop-2.6.0-cdh5.5.4.gz + hue-3.9.0-cdh5.5.4.tar.gz)(博主推荐) Hue的启动 也就是说,你Hue ...

  3. loj125 除数函数求和 2

    https://loj.ac/problem/125 $原式=2\sum_{i=1}^n(i^2*{\lfloor}{\frac{n}{i}}{\rfloor})+3\sum_{i=1}^n(i*{\ ...

  4. Android的代码适配方案

    public class DensityUtil { private DensityUtil(){ throw new AssertionError(); } /** * dp转px * @param ...

  5. 合理设置apache的连接数及进程工作方式

    网站在线人数增多,访问时很慢.初步认为是服务器资源不足了,但经反复测试,一旦连接上,不断点击同一个页面上不同的链接,都能迅速打开,这种现象就是说明apache最大连接数已经满了,新的访客只能排队等待有 ...

  6. 【转】几种Java序列化方式的实现

    0.前言 本文主要对几种常见Java序列化方式进行实现.包括Java原生以流的方法进行的序列化.Json序列化.FastJson序列化.Protobuff序列化. 1.Java原生序列化 Java原生 ...

  7. 【转】Java泛型方法

    1. 定义泛型方法 (1) 如果你定义了一个泛型(类.接口),那么Java规定,你不能在所有的静态方法.静态初块等所有静态内容中使用泛型的类型参数.例如: public class A<T> ...

  8. 在自己的工程中使用ijkplayer的功能

    最近在做一个软解视频叠加硬解视频的方案,网上看了很多教程,始终不得要领.虽然ijkplayer提供了ijkplayer-example这个示例工程,但对于初入安卓的人来说,要将ijkplayer整合到 ...

  9. spark性能优化-JVM虚拟机垃圾回收调优

    1 2 3 4

  10. xcopy递归拷贝

    递归拷贝 ::xcopy SOURCE_DIR DES_DIR\ /s SOURCE_DIR后面不需要加反斜杠