【链接】 我是链接,点我呀:)

【题意】

如果a[i]*2

【题解】

假设最后的方案是(ai,bi)
这里(ai,bi)表示下标为ai的袋鼠可以装进下标为bi的袋鼠里面
(这里袋鼠已经按照大小从小到大排序了)
则我们会发现,如果有(a1,b1),(a2,b2)...(ak,bk)这些方案的话(且这些方案合法)
我们总能让这个方案变成
a1~ak=1,2,3...k
b1~bk=n-k+1,n-k+2,n-k+3...n
因为对于每个(ai,bi)
ai只会减小,bi只会增大
那么下标为ai的袋鼠肯定还是小于下标为bi的袋鼠.
所以我们可以这么认为:
我们只会选择体型最小的x只袋鼠和体型最大的x只袋鼠进行配对装载
显然x另外一种错误的思路:

从大到小给每只袋鼠a[i]分配一个最大的且它能装得下的袋鼠a[j].

这种思路错误在于a[j]可能还可以给更小的袋鼠a[k]分配,

但是你把a[j]装下去了,可能除了a[j],a[i]之外没有其他袋鼠能装得下a[k]了。

比如例子:2 2 4 9

答案是2,但如果按照刚才说的错误思路的话,得到的答案会是3,因为9装了4之后,没有人能装2了

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)5e5;
static class Task{
int n;
int s[]; public void solve(InputReader in,PrintWriter out) {
s = new int[N+10];
n = in.nextInt();
for (int i = 1;i <= n;i++) {
s[i] = in.nextInt();
}
Arrays.sort(s, 1,n+1);
int x = 0;
int j = n; for (int i = n/2;i >= 1;i--) {
if (s[i]*2<=s[j]){
x++;j--;
}
}
out.println(n-x*2 + x);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 372A】Counting Kangaroos is Fun的更多相关文章

  1. 【codeforces 335E】 Counting Skyscrapers

    http://codeforces.com/problemset/problem/335/E (题目链接) 题意 懒得写了= = Solution 这题咋不上天= =. 参考题解:http://blo ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【41.43%】【codeforces 560C】Gerald's Hexagon

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. SSM整合配置错误记录

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dic ...

  2. E20180109-E

    auxilary  adj. 辅助的; 备用的,补充的; 附加的; 副的;               n. 助动词; 辅助者,辅助人员; 附属机构,附属团体; 辅助设备; 

  3. python/shell脚本报异常^M: bad interpreter: No such file or directory

    问题:在Windows写了一python脚本,上传Linux服务器执行,报异常*****^M: bad interpreter: No such file or directory 原因:window ...

  4. [转]C语言/C++中如何产生随机数

    C语言/C++怎样产生随机数:这里要用到的是rand()函数, srand()函数,和time()函数. 需要说明的是,iostream头文件中就有srand函数的定义,不需要再额外引入stdlib. ...

  5. web开发----jsp中通用模版的引用 include的用法

    1.静态引入的示例 通过对两种用法的了解之后  我们现在 使用静态引入 因为上述原因  我的模版页中 只有div  不会有 path等定义  也不会有html标签 如下: 我的header.jsp 全 ...

  6. ADPU 大全

    APDU协议 APDU协议,即是智能卡与读写器间的应用层协议,在ISO7816-4[7]中定义了该协议的结构格式.APDU数据有两种结构,读写器使用的APDU结构为命令APDU,C-APDU(Comm ...

  7. 【Python-2.7】删除空格

    有时我们在编程过程中,需要去除字符串两边的空格,可以用如下函数解决问题: rstrip():去除字符串右边的空格: lstrip():去除字符串左边的空格: strip():去除字符串两边的空格. 示 ...

  8. QS之shell script

    1 Invoke Mdoelsim In order to open Modelsim automatically, it is better to use a shell script to inv ...

  9. Java代码实现WORD转PDF

    第一步: 安装OpenOffice   在此良心提供windows版本安装文件 链接:https://pan.baidu.com/s/17pPCkcS1C46VtLhevqSgPw  密码:vmlu ...

  10. STL容器的排序

    STL容器的排序,支持随机访问的容器vector,deque,string没有sort成员,可调用std::sort排序:list排序调用自带的list::sort. 下面是std::sort函数,有 ...