• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #219 Div2 C

C. Counting Kangaroos is Fun
time limit per test 1 second
memory limit per test 256 megabytes
 这么简单的贪心都没想到!,难道就只知道首尾和相邻?这个是由于最多就n/2的数量,也尽量消耗n/2以内的大的,因为消耗了n/2以内的大的,即使用了最大的也没关系,如果这样了,n/2小的也有可能消耗,如果不这样,也就顶多用最大的消耗一个n/2稍微小的!

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 test(s)
Input
8 
2 5 7 6 9 8 4 2
Output
5
Input
8 
9 1 6 2 6 5 8 3
Output
5
 1 #include <cstdio>
 2 #include <vector>
 3 #include <cmath>
 4 #include <queue>
 5 #include <cstring>
 6 #include <iostream>
 7 #include <algorithm>
 8 using namespace std;
 9 #define INF 0x7fffffff
10 #define mod 1000000007
11 #define ll unsigned long long int
12 #define maxn 1005
13 int n, w, k, m, ans;
14 int dp[maxn][maxn];
15 int a[101000];
16 int main(){
17     cin >> n;
18     for (int i = 1; i <= n; i++)cin >> a[i];
19     sort(a + 1, a + n + 1);
20     int i = n,j = n / 2,ans=0;
21     while (i>=n/2&&j>0){
22         if (a[i] >= 2 * a[j])i--, j--, ans++;
23         else j--;
24     }
25     cout << n-ans;
26     return 0;
27 }
View Code
posted @ 2013-12-14 04:29  HaibaraAi  阅读(210)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3