[CodeForces 372A] Counting Kangaroos is Fun】的更多相关文章

题目链接: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 因为对于每…
题意,有n只袋鼠,没每只袋鼠有个袋子,大小为si,一个袋鼠可以进入另外一个袋鼠的袋子里面,当且仅当另一个袋鼠的袋子是他的二倍或二倍一上,然后中国袋鼠就是不可见的,不能出现多个袋鼠嵌套的情况.让你求最少可见袋鼠的数量. 解题方法是先排序再贪心,贪心策略是从中间开始贪心. #include <stdio.h> #include <algorithm> const int maxn = 500005; using namespace std; int s[maxn]; int n; in…
893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插空法)解决,要把一段分成y段,需要y-1个隔板,那么有y-1+k个位置,选y-1个位置为隔板,剩下的都是小球,那么方案数为C(y-1+k,y-1). 如果全为正数,答案就是所有质因子方案数的积. 但是这道题目可以为负数,那么在这y个数里选偶数个变成负数 答案还要乘以C(y,0)+C(y,2)+C(y…
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…
http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下角,左上角不超过i,j有多少矩形,然后询问的时候枚举右下角就可以了 #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<iostream> i…
题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6). 问你有多少种长度为y,乘积为x的整数数列.(可以有负数) 题解: 首先考虑数列只有正整数的情况. 将x分解质因数:x = ∑ a[i]*p[i] 由于x较大,所以要先用线性筛求出素数,再枚举素数分解质因数. 那么一个乘积为x的数列可以看做,将x的所有∑ p[i]个质因子,分配到了y个位置上. 设f(i)…
题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问(a,b,c,d),问你: 在以(a,b)为左上角,以(c,d)为左下角,围成的矩形范围中,有多少全是0的矩形. 题解: 这题是dp套dp…… 首先解决dp1: 表示状态: f[a][b][c][d] = Rectangles number 表示左上角为(a,b),右下角的范围在(c,d)以内的全0矩形的个数.…
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…
#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容易出错 { <…