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. 使用pytesseract识别验证码,报错WindowsError: [Error 2]

    问题现象: 按照网上的方式进行代码编写,使用pytesseract模块,然后导入指定图片进行解析,报错WindowsError: [Error 2] 问题原因: 源代码里面的路径设置错误,这里有一个坑 ...

  2. iOS NavigationBar 导航栏自定义

    1. 设置导航栏NavigationBar的背景颜色: a)  setBarTintColor : 设置NagivationBar的颜色 也可以用 : [[UINavigationBar appear ...

  3. Jquery实现相对浏览器位置固定、悬浮

      <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></sc ...

  4. Mirror Number SPOJ - MYQ10

    Mirror Number SPOJ - MYQ10 题意:http://blog.csdn.net/hcbbt/article/details/38349367 稍微改一下http://www.cn ...

  5. Distance in Tree CodeForces - 161D

    Distance in Tree CodeForces - 161D 题意:给一棵n个结点的树,任意两点之间的距离为1,现在有点u.v,且u与v的最短距离为k,求这样的点对(u,v)的个数((u,v) ...

  6. 牛客练习赛25-A-因数个数和

    题目描述 q次询问,每次给一个x,问1到x的因数个数的和. 输入描述: 第一行一个正整数q:接下来q行,每行一个正整数x 输出描述: 共q行,每行一个正整数表示答案 输入 4 1 2 3 10 输出 ...

  7. 147 Insertion Sort List 链表插入排序

    用插入排序对链表进行排序. 详见:https://leetcode.com/problems/insertion-sort-list/description/ Java实现: 链表的插入排序实现原理很 ...

  8. Android屏幕适配-安卓切图

    一.Android中的单位 1.dp(dip):density-independent pixels,这并不是一个绝对的单位,而只是一个相对的概念,代表的是屏幕写对角线上每inch上像素点的个数. 2 ...

  9. Nginx重写规则

    Nginx的重写规则,依赖于pcre库(perl compatible regular expression).所以在安装的时候一定要让nginx支持这个功能,以及安装pcre-devel,prce. ...

  10. mysql数据误删除(drop)的恢复. (ext3grep, extundelete)

    drop table tbl_name 物理删除.没有备份,没有二进制日志 在系统删除文件并非在存储中抹去数据,而仅仅是标识对应的block块可以被重新的分配使用.所以数据的恢复还是有希望的.但是那些 ...