题意,有n只袋鼠,没每只袋鼠有个袋子,大小为si,一个袋鼠可以进入另外一个袋鼠的袋子里面,当且仅当另一个袋鼠的袋子是他的二倍或二倍一上,然后中国袋鼠就是不可见的,不能出现多个袋鼠嵌套的情况。让你求最少可见袋鼠的数量。

解题方法是先排序再贪心,贪心策略是从中间开始贪心。

  1. #include <stdio.h>
  2. #include <algorithm>
  3. const int maxn = 500005;
  4.  
  5. using namespace std;
  6.  
  7. int s[maxn];
  8. int n;
  9.  
  10. int main()
  11. {
  12. while (scanf("%d", &n) != EOF)
  13. {
  14. for (int i = 1; i <= n; i++)
  15. {
  16. scanf("%d", &s[i]);
  17. }
  18. sort(s+1, s+n+1);
  19. int j = n/2 + 1;
  20. int ans = 0;
  21. for (int i = 1; i <= n>>1 && j <= n;)
  22. {
  23. if (s[j] >= 2*s[i])
  24. {
  25. ans++;
  26. i++;
  27. j++;
  28. }
  29. else
  30. {
  31. j++;
  32. }
  33. }
  34. printf("%d\n", n-ans);
  35. }
  36. return 0;
  37. }

CodeForces 372 A. Counting Kangaroos is Fun的更多相关文章

  1. Codeforces 372 B. Counting Rectangles is Fun

    $ >Codeforces \space 372 B.  Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...

  2. 【Codeforces 372A】Counting Kangaroos is Fun

    [链接] 我是链接,点我呀:) [题意] 如果a[i]*2<=a[j]那么i袋鼠可以装进j袋鼠里面 每只袋鼠都只能装一只袋鼠 [题解] 假设最后的方案是(ai,bi) 这里(ai,bi)表示下标 ...

  3. Codeforces 954H Path Counting 【DP计数】*

    Codeforces 954H Path Counting LINK 题目大意:给你一棵n层的树,第i层的每个节点有a[i]个儿子节点,然后问你树上的简单路径中长度在1~n*2-2之间的每个有多少条 ...

  4. codeforces 372 Complete the Word(双指针)

    codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #incl ...

  5. [CodeForces 372A] Counting Kangaroos is Fun

    题目链接:http://codeforces.com/problemset/problem/372/A 二分思想 AC代码: #include <cstdio> #include < ...

  6. Codeforces 372

    A (被装的袋鼠不可以装的袋鼠)贪心,排序,从n/2分成两部分. B 好一道前缀和的题目. C 标准算法不难想,m^2的算法见http://codeforces.com/blog/entry/9907 ...

  7. cf C. Counting Kangaroos is Fun

    http://codeforces.com/contest/373/problem/C 贪心,先排序,然后从n/2位置倒着找每一个可不可以放到别的袋鼠内. #include <cstdio> ...

  8. 【codeforces 335E】 Counting Skyscrapers

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

  9. Codeforces 911D. Inversion Counting (数学、思维)

    题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对. ...

随机推荐

  1. 补习系列(21)-SpringBoot初始化之7招式

    目录 背景 1. @PostConstruct 注解 2. InitializingBean 接口 3. @Bean initMethod方法 4. 构造器注入 5. ApplicationListe ...

  2. 【对象属性复制】BeanUtils.copyProperties(obj1, obj2);

    实现对象的属性值复制,只会复制命名相同的文件. import org.springframework.beans.BeanUtils; BeanUtils.copyProperties(obj1, o ...

  3. 【数据结构--二叉树】Java递归实现二叉树遍历

    参考链接:https://www.cnblogs.com/yaobolove/p/6213936.html 这有一棵树: 1.节点对象 package com.tree.mybinarytree; / ...

  4. 【Shell学习笔记3》实践项目自动部署脚本】shell中获取返回值、获取当前sh文件路径

    原创部分: 1.获取返回值 #This is a shell to Deploy Project #!/bin/bashcheck_results=`ps -ef | grep "java& ...

  5. Django生成PDF显示在网页上以及解决中文显示乱码的问题

    项目地址:https://github.com/PythonerKK/django-generate-pdf/tree/master 这个demo实现了通过用户输入自己的个人信息生成一份简历pdf,来 ...

  6. 4.shell编程-文本处理三剑客之sed

    4.1.sed的选项 sed,流编辑器.对标准输出或文件进行逐行处理. 语法格式 第一种:stdout | sed [option] "pattern command" 第二种:s ...

  7. 浅谈block, inline和inline-block的区别

    block 块元素    inline 内联元素 常见的块元素有:div, p, h1~h6, table, form, ol, ul等 常见的内联元素有:span, a, strong, em, l ...

  8. 使用JavaScript带你体验V8引擎解析字符串过程

    AST模块其实要写的话,100篇都写不完,我将一些简单知识点翻译成JavaScript代码来进行讲解(v8内部的复杂性永远都能超出我的意料,现在看到万行的源码都已经没感觉了),如果谁想看C++源码,就 ...

  9. jquery对下拉框的操作

     jQuery对下拉框的操作 /获取第一个option的值 $('#test option:first').val(); //最后一个option的值 $('#test option:last').v ...

  10. 《转载黑马教程》HTML&&CSS讲义0,,包含教程_仅供参考

    今日内容 1. web概念概述 2. HTML web概念概述 * JavaWeb: * 使用Java语言开发基于互联网的项目 * 软件架构: 1. C/S: Client/Server 客户端/服务 ...