A. Counting Kangaroos is Fun(贪心)】的更多相关文章

Problem 计算袋鼠是愉快的 题目大意 有n只袋鼠,如果一个袋鼠体积是另一个袋鼠的两倍或以上,则小袋鼠能被大袋鼠装进袋子里,装进去后就看不到袋子里的袋鼠了,问这群袋鼠如何行动才能使得它们看着数量最少,请输出该数量.(注意,如果一个小袋鼠被装在袋子里,则小袋鼠袋子里不能再嵌套袋鼠了) 也就是给出一个数组,求这个数组中最多的u,v使得u>=2v,每个数组中的数只能作为一次u,v (具体还是直接看题吧) Solution 首先我们考虑最优情况,一定有:最小ans≥n/2,这是题目限制条件可得的.…
#include<stdio.h> #include<algorithm> using namespace std; ]; int main() { int i,n,high; while(scanf("%d",&n)!=EOF) { ;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int ans=n; high=n-; -;i>=;i--)//i=n/2-1容易出错 { <…
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 w…
http://codeforces.com/contest/373/problem/C 贪心,先排序,然后从n/2位置倒着找每一个可不可以放到别的袋鼠内. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 5000001 using namespace std; int a[maxn]; bool vis[maxn]; int n; int main() { while(scan…
题意,有n只袋鼠,没每只袋鼠有个袋子,大小为si,一个袋鼠可以进入另外一个袋鼠的袋子里面,当且仅当另一个袋鼠的袋子是他的二倍或二倍一上,然后中国袋鼠就是不可见的,不能出现多个袋鼠嵌套的情况.让你求最少可见袋鼠的数量. 解题方法是先排序再贪心,贪心策略是从中间开始贪心. #include <stdio.h> #include <algorithm> const int maxn = 500005; using namespace std; int s[maxn]; int n; in…
题目链接:http://codeforces.com/problemset/problem/372/A 二分思想 AC代码: #include <cstdio> #include <algorithm> using namespace std; int arr[500005]; int main() { int n; while(scanf("%d",&n) != EOF) { for(int i = 0;i < n;i++) { scanf(&q…
[链接] 我是链接,点我呀:) [题意] 如果a[i]*2<=a[j]那么i袋鼠可以装进j袋鼠里面 每只袋鼠都只能装一只袋鼠 [题解] 假设最后的方案是(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 因为对于每…
As most of the ACMers, wy's next target is algorithms, too. wy is clever, so he can learn most of the algorithms quickly. After a short time, he has learned a lot. One day, mostleg asked him that how many he had learned. That was really a hard proble…
%%%Luan 题面就不说了,和斗地主一样,给一组牌,求最少打几次. 注意一点,数据随机,这样我们瞎搞一搞就可以过,虽然直接贪心可以证明是错的. 枚举方法,每次搜索按照(三顺子>二顺子>普通顺子)枚举一个进入下一层搜索. 在每层搜索中我们都要枚举打其他牌的方法,用贪心的结果+顺子数来更新答案. 具体方法是(想象你手里有这么多牌你该怎么打),枚举四代二,四代一,三代二,三代一,对和单. 注意我要带的必须是恰好两个或一个,不然会被随机数据hack.. Code #include<iostre…
Illegal spices 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1995 Description Jabba: Han, my boy, you disappoint me. Why haven't you paid me? And why did you fry poor Greedo? Han: Look, Jabba, next time you wanna talk to me, come see me yourself…