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. AtCoder Grand Contest 008 D - K-th K

    题目传送门:https://agc008.contest.atcoder.jp/tasks/agc008_d 题目大意: 给你一个长度为\(N\)的序列\(A\),请你构造一个长度为\(N^2\)的序 ...

  2. PTA天梯赛训练题L1-064:估值一亿的AI核心代码(字符串模拟)

    Update:smz说regex秒过Orz,yzd记在这里了. 听说今年天梯赛有个烦人的模拟,我便被队友逼着试做一下……一发15,二发20.记一记,要不然枉费我写这么久…… 自己还是代码能力太菜了,校 ...

  3. sql基础语法-联接查询

    交叉联接 1.不带where条件的,将返回两个表的 行乘积 select c.*, e.* from Sales.Customers c cross join hr.Employees e 2.带wh ...

  4. 启动azkaban时出现User xml file conf/azkaban-users.xml doesn't exist问题解决(图文详解)

      问题详情 [hadoop@master azkaban]$ ll total drwxrwxr-x hadoop hadoop May : azkaban- drwxrwxr-x hadoop h ...

  5. asp.net 微信登录实现方式

    之前我以为做微信登录跟微信公众号有关,后来发现是我想多了.原来微信还有一个叫开放平台的东西,见下图: 我的这个已经生成好了,没有的需要创建一个,https://open.weixin.qq.com/c ...

  6. P3372 【模板】线段树 1 区间查询与区间修改

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个 ...

  7. 搭建SSM框架(聚合项目)

    parents 父工程 pom  base用户权限 jar   wms业务 jar app帮助管理 war1. parents的pom.xml文件 1.1 maven servlet3.1.0 1.2 ...

  8. 6 Specialzed layers 特殊层 第二部分 读书笔记

    CAGradientLayer   CAGradientLayer is used to generate a smooth gradient between two or more colors. ...

  9. Java子类与父类方法的隐藏和覆盖

    class Base{     int x = 1;     static int y = 2;     String name(){         return "mother" ...

  10. qt project settings被禁用解决方案

    转载请注明出处:http://www.cnblogs.com/dachen408/p/7422707.html qt project settings被禁用点击不了: 解决方案:需要点击该项目(或者项 ...