第三届华中区程序设计邀请赛暨武汉大学第十二届校赛 网络预选赛 水题解题报告
2014-03-31 09:08
357 查看
Problem 1537 - A - Stones I
Time Limit: 1000MS Memory Limit: 65536KB
Total Submit: 470 Accepted: 72 Special Judge: No
Description
Xiaoming took the flight MH370 on March 8, 2014 to China to take the ACM contest in WHU. Unfortunately, when the airplane crossing the ocean, a beam of mystical light suddenly lit up the sky and all the passengers with the airplane were transferred to another desert planet.
When waking up, Xiaoming found himself lying on a planet with many precious stones. He found that:
There are n precious stones lying on the planet, each of them has 2 positive values ai and bi. Each time Xiaoming can take the ith of the stones ,after that, all of the stones’ aj (including the stones Xiaoming has taken) will cut down bi units.
Xiaoming could choose arbitrary number (zero is permitted) of the stones in any order. Thus, he wanted to maximize the sum of all the stones he has been chosen. Please help him.
Input
The input consists of one or more test cases.
First line of each test case consists of one integer n with 1 <= n <= 1000.
Then each of the following n lines contains two values ai and bi.( 1<= ai<=1000, 1<= bi<=1000)
Input is terminated by a value of zero (0) for n.
Output
For each test case, output the maximum of the sum in one line.
Sample Input
1
100 100
3
2 1
3 1
4 1
0
Sample Output
0
3
Hint
Source
简单贪心策略,枚举取石头的个数。
Time Limit: 1000MS Memory Limit: 65536KB
Total Submit: 470 Accepted: 72 Special Judge: No
Description
Xiaoming took the flight MH370 on March 8, 2014 to China to take the ACM contest in WHU. Unfortunately, when the airplane crossing the ocean, a beam of mystical light suddenly lit up the sky and all the passengers with the airplane were transferred to another desert planet.
When waking up, Xiaoming found himself lying on a planet with many precious stones. He found that:
There are n precious stones lying on the planet, each of them has 2 positive values ai and bi. Each time Xiaoming can take the ith of the stones ,after that, all of the stones’ aj (including the stones Xiaoming has taken) will cut down bi units.
Xiaoming could choose arbitrary number (zero is permitted) of the stones in any order. Thus, he wanted to maximize the sum of all the stones he has been chosen. Please help him.
Input
The input consists of one or more test cases.
First line of each test case consists of one integer n with 1 <= n <= 1000.
Then each of the following n lines contains two values ai and bi.( 1<= ai<=1000, 1<= bi<=1000)
Input is terminated by a value of zero (0) for n.
Output
For each test case, output the maximum of the sum in one line.
Sample Input
1
100 100
3
2 1
3 1
4 1
0
Sample Output
0
3
Hint
Source
简单贪心策略,枚举取石头的个数。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 1010; int a , b , c ; bool cmp(int x, int y){ return x > y; } int main(){ int n; while(scanf("%d", &n) != EOF && n){ for(int i = 0; i < n; i++) scanf("%d%d", &a[i], &b[i]); int ans = -0x3fffffff; for(int k = 1; k <= n; k++){ for(int i = 0; i < n; i++) c[i] = a[i] - k * b[i]; sort(c, c + n, cmp); int sum = 0; for(int i = 0; i < k; i++){ sum += c[i]; } // cout << k << " " << ans << endl; ans = max(ans, sum); } printf("%d\n", ans); } return 0; }
相关文章推荐
- 第二届华中区程序设计邀请赛暨武汉大学第十一届校赛 网络预选赛 解题报告
- 第二届华中区程序设计邀请赛暨武汉大学第十一届校赛 网络预选赛 解题报告
- 第二届华中区程序设计邀请赛暨武汉大学第十一届校赛 网络预选赛 解题报告
- 第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛
- 第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛 Problem 1566 - C - Spanning Tree
- 第二届华中区程序设计邀请赛暨武汉大学第十一届校赛 现场赛 解题报告
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛
- 15.4.19 第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛 A
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛 A Minimum Sum 树状数组
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛 E Calculation 状态压缩DP枚举子集
- C - Spanning Tree 最小生成树 Kruskal (第四届华中区程序设计邀请赛暨武汉大学第十三届校赛)
- 首届华中区程序设计邀请赛暨第十届武汉大学程序设计大赛网络预赛A题(HDOJ-4215)
- 首届华中区程序设计邀请赛暨第十届武汉大学程序设计大赛网络预赛I题(HDOJ-4223)
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 Problem 1608 - Calculation
- 首届华中区程序设计邀请赛暨第十届武汉大学程序设计大赛网络预赛G题(HDOJ-4221)
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 现场赛 WHU oj Problem 1613 - Count in Sama’s triangle 扩展欧几里得
- 首届华中区程序设计邀请赛暨第十届武汉大学程序设计大赛网络预赛C题(HDOJ-4217)
- 2017华中区邀请赛暨武汉大学校赛网络赛小结 + WOJ 642 Lost in WHU