hdu 4296 Buildings(贪婪)
主题链接:http://acm.hdu.edu.cn/showproblem.php?
pid=4296
Buildings
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.
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).
If no floor would be damaged in a optimal configuration (that is, minimal PDV is non-positive) you should output 0.
3
10 6
2 3
5 4
2
2 2
2 2
3
10 3
2 5
3 3
1
0
2
#include <cstdio>
typedef __int64 LL;
int main()
{
int n;
LL s, w;
LL maxx;
while(~scanf("%d",&n))
{
maxx = 0;
LL sum = 0, ans;
for(int i = 0; i < n; i++)
{
scanf("%I64d%I64d",&w,&s);
sum += w;
if(s + w > maxx)//s+w最大的一组把大部分的下面
maxx = s + w;
}
ans = sum-maxx;
printf("%I64d\n",ans);
}
return 0;
}
hdu 4296 Buildings(贪婪)的更多相关文章
- HDU 4296 Buildings(贪心)
题意: 给定n个建筑物,每个建筑物都有两个属性w, s,每个建筑物都有一个PDV = (Σw j)-s i .意思就是它上面的所有的w相加减去它的s,让求怎么放置这个建筑物使得每个建筑物当中PDV最大 ...
- HDU 4296 Buildings (YY)
题意: 给定N个物体,每个物体有两个参数w,s. w代表它自身的重量: s代表它的强度.现在要把这些物体叠在一起,会产生一个PDV值. PDV解释:(Σwj)-si, where (Σwj) st ...
- HDU 5301 Buildings 数学
Buildings 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5301 Description Your current task is to m ...
- hdu 5301 Buildings (2015多校第二场第2题) 简单模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子 ...
- HDU - 5301 Buildings
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- HDU 5301 Buildings(2015多校第二场)
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- hdu 4296 贪心
证明转自: here 题意:有 n 个地板,每个地板 i 有两个权值 Wi, Si,且 PDV(i) = (ΣWj) - Si ( j 表示在 i 上面的地板).问如何调整顺序,使得[max(PD ...
- HDU 5301 Buildings 建公寓(逻辑,水)
题意:有一个包含n*m个格子的矩阵,其中有一个格子已经被染黑,现在要拿一些矩形来填充矩阵,不能填充到黑格子,但是每一个填充进去的矩形都必须至少有一条边紧贴在矩阵的边缘(4条边)的.用于填充的矩形其中最 ...
随机推荐
- 新出台的治理iMessage垃圾短信的规则
工信部拟制定<通信短信息服务管理规定>,为治理垃圾短信提供执法根据.当中,对于苹果iMessage垃圾信息泛滥现象,工信部也将跟踪研究技术监測和防范手段.这意味着长期以来处于监管" ...
- hdu5171(矩阵快速幂)
传送门:GTY's birthday gift 题意:GTY的朋友ZZF的生日要来了,GTY问他的基友送什么礼物比较好,他的一个基友说送一个可重集吧!于是GTY找到了一个可重集S,GTY能使用神犇魔法 ...
- poj1860(spfa判正环)
题目连接:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 money=(nowmoney-手续费)*rat ...
- Linux下SVN安装配置全程实录(转)
一.安装SVN默认安装到/usr/local/bin下面 二.创建仓库 svnadmin create /home/svnrepo /root/svnrepo为所创建仓库的路径,理论上可以是任何目录 ...
- 怎样使用docker不加sudo
有时候发现docker有的指令必须加sudo才干运行,通过下面三步设置便可不加sudo直接运行docker指令: 1. 假设还没有docker group就加入一个: sudo groupadd do ...
- python面向对象具体解释(上)
创建类 Python 类使用 class 关键字来创建.简单的类的声明能够是关键字后紧跟类名: class ClassName(bases): 'class documentation string' ...
- Java集合关于ArrayList
ArrayList实现源码分析 2016-04-11 17:52 by 淮左, 207 阅读, 0 评论, 收藏, 编辑 本文将以以下几个问题来探讨ArrayList的源码实现1.ArrayList的 ...
- 如何通过shell脚本操作MongoDB
通过shell脚本对MongoDB进行自动化操作 运行写好的 ./show.sh 脚本 发现能够建立mongo链接 #!/bin/sh mongo WordPress --eval "sho ...
- C++——STL中三种顺序容器的简要差别
C++ STL 提供了3个顺序容器 :vector, deque, list Vector动态数组.支持高速訪问:list双向链表,支持高速插入和删除. vector 中的元素是顺序存放的.所以随机訪 ...
- Linux C语言写的超级简单port扫描器
这个本来曾经也写过的,今天无聊复习下 再写一遍.简单的一塌糊涂,写的不咋地大家见谅哦!有空再加强 嘿嘿! #include <stdio.h> #include <stdlib.h& ...