您的位置:首页 > 其它

CodeForces 372A Counting Kangaroos is Fun袋鼠口袋问题折半搜索

2016-07-27 08:58 323 查看
Counting Kangaroos is Fun
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u
Submit Status

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
58
3


Output
5

题意说是有n个袋鼠,口袋A<=2*口袋B,那么这个小袋鼠能被大的袋鼠装下,现在让尽量多的袋鼠被装下,求这个状态的最小值;先将所有袋鼠按口袋大小排序,然后贪心搜索

#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int a[1000000];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int p=n-1;
for (int i =n/2-1;i>=0; i--)//将排好序的袋鼠分为两部分,然后枚举搜索
{
if (a[i]*2<=a[p])
{
p--;
}
}
printf("%d\n",p+1);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: