Buildings HDU 4296
来源:互联网 发布:网络刷到被骗了怎么办 编辑:程序博客网 时间:2024/05/21 14:54
Buildings
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4258 Accepted Submission(s): 1579
Problem Description
Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.Mary has accomplished many great projects, one of which is the Guanghua Building.
The public opinion is that Guanghua Building is nothing more than one of hundreds of modern skyscrapers recently built in Shanghai, and sadly, they are all wrong. Blue.Mary the great civil engineer had try a completely new evolutionary building method in project of Guanghua Building. That is, to build all the floors at first, then stack them up forming a complete building.
Believe it or not, he did it (in secret manner). Now you are face the same problem Blue.Mary once stuck in: Place floors in a good way.
Each floor has its own weight wi and strength si. When floors are stacked up, each floor has PDV(Potential Damage Value) equal to (Σwj)-si, where (Σwj) stands for sum of weight of all floors above.
Blue.Mary, the great civil engineer, would like to minimize PDV of the whole building, denoted as the largest PDV of all floors.
Now, it’s up to you to calculate this value.
The public opinion is that Guanghua Building is nothing more than one of hundreds of modern skyscrapers recently built in Shanghai, and sadly, they are all wrong. Blue.Mary the great civil engineer had try a completely new evolutionary building method in project of Guanghua Building. That is, to build all the floors at first, then stack them up forming a complete building.
Believe it or not, he did it (in secret manner). Now you are face the same problem Blue.Mary once stuck in: Place floors in a good way.
Each floor has its own weight wi and strength si. When floors are stacked up, each floor has PDV(Potential Damage Value) equal to (Σwj)-si, where (Σwj) stands for sum of weight of all floors above.
Blue.Mary, the great civil engineer, would like to minimize PDV of the whole building, denoted as the largest PDV of all floors.
Now, it’s up to you to calculate this value.
Input
There’re several test cases.
In each test case, in the first line is a single integer N (1 <= N <= 105) denoting the number of building’s floors. The following N lines specify the floors. Each of them contains two integers wi and si (0 <= wi, si <= 100000) separated by single spaces.
Please process until EOF (End Of File).
In each test case, in the first line is a single integer N (1 <= N <= 105) denoting the number of building’s floors. The following N lines specify the floors. Each of them contains two integers wi and si (0 <= wi, si <= 100000) separated by single spaces.
Please process until EOF (End Of File).
Output
For each test case, your program should output a single integer in a single line - the minimal PDV of the whole building.
If no floor would be damaged in a optimal configuration (that is, minimal PDV is non-positive) you should output 0.
If no floor would be damaged in a optimal configuration (that is, minimal PDV is non-positive) you should output 0.
Sample Input
310 62 35 422 22 2310 32 53 3
Sample Output
102题目大意:建高楼:建一个多少层的楼层,每层楼有一个pdv,和重量两个属性,判断那种排列顺序的代表pdv最小;首先给出楼层信息,有多种排列次序,最好的排列顺序就是把weight+pdv做大的放在最下边(单独把最重的或者最能抗的放在最下边都还是不妥的,唯有综合两种之和才是最合适的,可以自己验证),找到这种方式后,依次求一下各楼层的楼上总weight-改成pdv,求出最大值;#include<iostream>#include<algorithm>using namespace std;struct Floor{long long x,y;};bool cmp(Floor m,Floor n){return (m.x+m.y)<(n.x+n.y);}int main(){int i,j,n;int x;Floor a[100000];while(scanf("%d",&n)!=EOF){long long sum=0;long long min=0;for(i=1;i<=n;i++){scanf("%Id%Id",&a[i].x,&a[i].y);}sort(a+1,a+n+1,cmp);for(i=1;i<=n;i++){min=max(min,sum-a[i].y);sum+=a[i].x;}printf("%I64d\n",min);}return 0;}
阅读全文
0 0
- [hdu] 4296 Buildings
- HDU 4296 Buildings
- HDU 4296 Buildings
- hdu 4296 Buildings
- hdu - 4296 - Buildings
- HDU 4296 buildings
- hdu 4296(buildings)
- hdu-4296-Buildings
- HDU 4296 Buildings(贪心)
- HDU-4296-Buildings
- hdu 4296 Buildings(贪心)
- HDU 4296 Buildings
- 贪心-- HDU - 4296 Buildings
- hdu 4296 Buildings
- hdu 4296 Buildings
- HDU 4296 Buildings 贪心
- HDU 4296 Buildings
- Buildings HDU 4296
- (牛客网)二维数组中的查找
- python——修改Dataframe列名的两种方法
- Spring注入property认识
- MySql语句
- WIN 下安装Django 的方法
- Buildings HDU 4296
- JavaScript类型比较
- LeetCode 134 Gas Station 题解
- Android通知栏微技巧,那些你所没关注过的小细节
- Kotlin 官方学习教程之接口
- SpringMVC数据绑定1 之 基本对象、数组、包装类与集合的绑定
- ROS(三) 在gazebo中创建自己的机器人模型
- make 重定向输出
- HDU1065(数学水题)