主题链接:http://acm.hdu.edu.cn/showproblem.php?

pid=4296

Buildings

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1822    Accepted Submission(s): 722
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.
 
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).
 
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.
 
Sample Input
3
10 6
2 3
5 4
2
2 2
2 2
3
10 3
2 5
3 3
 
Sample Output
1
0
2
 
Source

代码例如以下:
#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(贪婪)的更多相关文章

  1. HDU 4296 Buildings(贪心)

    题意: 给定n个建筑物,每个建筑物都有两个属性w, s,每个建筑物都有一个PDV = (Σw j)-s i .意思就是它上面的所有的w相加减去它的s,让求怎么放置这个建筑物使得每个建筑物当中PDV最大 ...

  2. HDU 4296 Buildings (YY)

    题意: 给定N个物体,每个物体有两个参数w,s.   w代表它自身的重量: s代表它的强度.现在要把这些物体叠在一起,会产生一个PDV值. PDV解释:(Σwj)-si, where (Σwj) st ...

  3. HDU 5301 Buildings 数学

    Buildings 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5301 Description Your current task is to m ...

  4. hdu 5301 Buildings (2015多校第二场第2题) 简单模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子 ...

  5. HDU - 5301 Buildings

    Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...

  6. HDU 5301 Buildings(2015多校第二场)

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  7. 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 ...

  8. hdu 4296 贪心

    证明转自:  here 题意:有 n 个地板,每个地板 i 有两个权值 Wi, Si,且 PDV(i) =  (ΣWj) - Si ( j 表示在 i 上面的地板).问如何调整顺序,使得[max(PD ...

  9. HDU 5301 Buildings 建公寓(逻辑,水)

    题意:有一个包含n*m个格子的矩阵,其中有一个格子已经被染黑,现在要拿一些矩形来填充矩阵,不能填充到黑格子,但是每一个填充进去的矩形都必须至少有一条边紧贴在矩阵的边缘(4条边)的.用于填充的矩形其中最 ...

随机推荐

  1. 微信支付.net官方坑太多,我们来精简

    原文:微信支付.net官方坑太多,我们来精简 微信支付官方坑太多,我们来精简 我把官方的代码,打包成了 an.wxapi.dll. 里面主要替换了下注释.呵呵.然后修改了几个地方. 修改一.Confi ...

  2. 我在开发网站后得出的asp.Net网站优化总结

    原文:我在开发网站后得出的asp.Net网站优化总结 asp.Net网站优化总结: 1.数据库优化: 首先是对查询语句的优化,开发时为了图快可以不考虑,但是后期维护时就必须要优化(比如:你调用代码生成 ...

  3. POJ 1018 【枚举+剪枝】.cpp

    题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...

  4. OpenCV 通过 MFC 的 Picture Control 控件操作图像

    假设希望对显示在MFC Picture Control 控件里的图像进行操作,比方画线画点之类的,能够利用 OpenCV 结合 MFC 本身的鼠标响应函数来实现. 怎样将图像显示到 Picture C ...

  5. Scala的XML操作

     8.  XML 8.1.     生成 Scala原生支持xml,就如同Java支持String一样,这就让生成xml和xhtml非常easy优雅: val name = "james ...

  6. Mina框架断包、粘包问题解决方式

    Mina框架断包.粘包问题解决方式 Apache Mina Server 是一个网络通信应用框架,也就是说,它主要是对基于TCP/IP.UDP/IP协议栈的通信框架(当然.也能够提供JAVA 对象的序 ...

  7. Android - 通过Intent启动Activity

    通过Intent启动Activity 本文地址: http://blog.csdn.net/caroline_wendy 为了动态关联Activity界面,使用Intent启动.能够灵活绑定. 在In ...

  8. Tomcat6 Session建立机制简要

    底:  测试部门做压力测试, 结果没多久新闻,出现OutOfMemory. 查找原因,通过监视工具,查找StandardSession(org.apache.catalina.session.Stan ...

  9. hdu 1698 Just a Hook(线段树之 成段更新)

    Just a Hook                                                                             Time Limit: ...

  10. Openfire开发配置,Openfire源码配置,OpenFire二次开发配置

    1.下载源码:http://www.igniterealtime.org/downloads/source.jsp 2.把源码解压出的openfire_src目录放至eclipse workplace ...