The 2016 ACM-ICPC Asia China-Final C (15/600)
2017-06-14 14:27
337 查看
Mr. Panda likes ice cream very much especially the ice cream tower. An ice cream tower consists
of K ice cream balls stacking up as a tower. In order to make the tower stable, the lower ice cream
ball should be at least twice as large as the ball right above it. In other words, if the sizes of the
ice cream balls from top to bottom are A0, A1, A2, · · · , AK−1, then A0 × 2 ≤ A1, A1 × 2 ≤ A2,
etc.
One day Mr. Panda was walking along the street and found a shop selling ice cream balls. There
are N ice cream balls on sell and the sizes are B0, B1, B2, · · · , BN−1. Mr. Panda was wondering
the maximal number of ice cream towers could be made by these balls.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test
case starts with a line consisting of 2 integers, N the number of ice cream balls in shop and K
the number of balls needed to form an ice cream tower. The next line consists of N integers
representing the size of ice cream balls in shop.
Output
For each test case, output one line containing “Case #x: y”, where x is the test case number
(starting from 1) and y is the maximal number of ice cream towers could be made.
Limits
• 1 ≤ T ≤ 100.
• 1 ≤ N ≤ 3 × 105
.
• 1 ≤ K ≤ 64.
• 1 ≤ Bi ≤ 1018
.
Sample input and output
Sample Input Sample Output
3
4 2
1 2 3 4
6 3
1 1 2 2 4 4
6 3
1 1 2 2 3 4
Case #1: 2
Case #2: 2
Case #3: 1
就是个普通的二分….枚举答案
看行不行
检测的时候只要一层一层的贪心就可以了。。更大的不行那小的也不行
of K ice cream balls stacking up as a tower. In order to make the tower stable, the lower ice cream
ball should be at least twice as large as the ball right above it. In other words, if the sizes of the
ice cream balls from top to bottom are A0, A1, A2, · · · , AK−1, then A0 × 2 ≤ A1, A1 × 2 ≤ A2,
etc.
One day Mr. Panda was walking along the street and found a shop selling ice cream balls. There
are N ice cream balls on sell and the sizes are B0, B1, B2, · · · , BN−1. Mr. Panda was wondering
the maximal number of ice cream towers could be made by these balls.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test
case starts with a line consisting of 2 integers, N the number of ice cream balls in shop and K
the number of balls needed to form an ice cream tower. The next line consists of N integers
representing the size of ice cream balls in shop.
Output
For each test case, output one line containing “Case #x: y”, where x is the test case number
(starting from 1) and y is the maximal number of ice cream towers could be made.
Limits
• 1 ≤ T ≤ 100.
• 1 ≤ N ≤ 3 × 105
.
• 1 ≤ K ≤ 64.
• 1 ≤ Bi ≤ 1018
.
Sample input and output
Sample Input Sample Output
3
4 2
1 2 3 4
6 3
1 1 2 2 4 4
6 3
1 1 2 2 3 4
Case #1: 2
Case #2: 2
Case #3: 1
就是个普通的二分….枚举答案
看行不行
检测的时候只要一层一层的贪心就可以了。。更大的不行那小的也不行
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; long long n, m, tu[300001],bj[300001]; long long jiance(long long k) { memset(bj, 0, sizeof(bj)); long long p = 0; for (long long a = 1; a <= k; a++)bj[a] = tu[++p]; for (long long a = 1; a < m; a++) { for (long long b = 1; b <= k; b++) { p++; while (p <= n&&tu[p] < 2 * bj[b])p++; if (p > n)return 0; bj[b] = tu[p]; } } return 1; } int main() { long long T; cin >> T; long long u = 0; while(T--) { cin >> n >> m; for (long long a = 1; a <= n; a++)scanf("%lld", &tu[a]); sort(tu + 1, tu + n + 1); long long y = n / m, z = 0; long long jieg = 0; while (z <= y) { long long mid = (z + y) / 2; if (jiance(mid)) { jieg = mid; z = mid + 1; } else y = mid - 1; } printf("Case #%lld: %lld\n", ++u, jieg); } }
相关文章推荐
- The 2016 ACM-ICPC Asia China-Final Contest H题 数学 + 思维
- Ice Cream Tower The 2016 ACM-ICPC Asia China-Final Contest
- Problem D. Ice Cream Tower (The 2016 ACM-ICPC Asia China-Final Contest)(二分)
- [费用流] ACM-ICPC Asia China-Final Contest J. Mr.Panda and TubeMaster
- The 2016 ACM-ICPC Asia Tehran Regional Contest 部分题解!
- HDU 5883 The Best Path(2016 ACM/ICPC Asia Regional Qingdao Online)
- The 2016 ACM-ICPC Asia Dalian Regional Contest(汇总)
- 2016 ACM-ICPC Asia Regional B – Help the Princess!(bfs)
- The 2016 ACM-ICPC Asia Dalian Regional Contest
- UVALive - 7711 The 2016 ACM-ICPC Asia Jakarta Regional Contest A - Confusing Date Format
- HDU 5883 The Best Path(并查集+欧拉回路 or 欧拉路)——2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5883 The Best Path 2016 ACM/ICPC Asia Regional Qingdao Online
- UVALive - 7720 The 2016 ACM-ICPC Asia Jakarta Regional Contest J - Super Sum
- HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
- UVALive - 7722 The 2016 ACM-ICPC Asia Jakarta Regional Contest L - Tale of a Happy Man dp+线段树
- UVALive - 7714 The 2016 ACM-ICPC Asia Jakarta Regional Contest D - Pay Day 脑洞+组合数学
- 1006 ACM again- Ancient China Mathematics again //The ACM/ICPC Asia Harbin Online First Round Contest 2010 Warmup-2
- UVALive - 7715 The 2016 ACM-ICPC Asia Jakarta Regional Contest E - Guessing Game 繁琐的等差数列求和
- HDU 5883 The Best Path (欧拉通路) 2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5879 Cure(技巧)——2016 ACM/ICPC Asia Regional Qingdao Online