题意: 给定N个物体,每个物体有两个参数w,s。   w代表它自身的重量; s代表它的强度。现在要把这些物体叠在一起,会产生一个PDV值。

PDV解释:(Σwj)-si, where (Σwj) stands for sum of weight of all floors above.即为在i物体上方所有物体的重量和 - i的强度。

现在希望最大的PDV值最小....................

YY: 假设两个物体i,j,把谁放上面比较好? 假设把i放上面,则pdv1 = Wi - Sj;把j放上面 则pdv2 = Wj - Si;要使得pdv尽量小,设pdv1 < pdv2 则 Wi + Si < Wj + Sj

所以按照w+s由小到大sort,就能满足条件了......

#include <iostream>
#include <algorithm>
#include <cmath>
#include<functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <climits>//形如INT_MAX一类的
#define MAX 100005
#define INF 0x7FFFFFFF
using namespace std; struct node {
int w,s;
}a[MAX];
int n; bool cmp(const node &x, const node &y) {
return x.w + x.s < y.w + y.s;
}
int main() {
while(scanf("%d",&n) != EOF) {
for(int i=0; i<n; i++) {
scanf("%d%d",&a[i].w,&a[i].s);
}
sort(a,a+n,cmp);
__int64 sum = 0;
__int64 pdv = -INF;
for(int i=1; i<n; i++) {
sum += a[i-1].w;
pdv = max(pdv,sum - a[i].s);
}
if(pdv < 0) printf("0\n");
else printf("%I64d\n",pdv);
}
return 0;
}

HDU 4296 Buildings (YY)的更多相关文章

  1. hdu 4296 Buildings(贪婪)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others ...

  2. HDU 5934 Bomb(炸弹)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. HDU 5734 Acperience(返虚入浑)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  4. HDU 5724 Chess(国际象棋)

    HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  5. HDU 5826 physics(物理)

     physics(物理) Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   D ...

  6. HDU 5835 Danganronpa(弹丸论破)

     Danganronpa(弹丸论破) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ)

    HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  8. HDU 5976 Detachment(拆分)

    HDU 5976 Detachment(拆分) 00 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem D ...

  9. HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spheric ...

随机推荐

  1. paip.输入法编程---输入法ATIaN历史记录 c823

    paip.输入法编程---输入法ATIaN历史记录 c823 作者Attilax ,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csd ...

  2. source insight 中文注释为乱码解决

    1. source insight 中文注释为乱码解决 http://blog.csdn.net/bingfeng1210/article/details/7527059 2. Source Insi ...

  3. iOS开发网络数据之AFNetworking使用1

    链接地址:http://blog.csdn.net/daiyelang/article/details/38421341 如何选择AFNetworking版本 官网下载2.5版本:http://afn ...

  4. WCF技术剖析之二十五: 元数据(Metadata)架构体系全景展现[元数据描述篇]

    原文:WCF技术剖析之二十五: 元数据(Metadata)架构体系全景展现[元数据描述篇] 在[WS标准篇]中我花了很大的篇幅介绍了WS-MEX以及与它相关的WS规范:WS-Policy.WS-Tra ...

  5. char、signed char 和 unsigned char 的区别

    ANSI C 提供了3种字符类型,分别是char.signed char.unsigned char.而不是像short.int一样只有两种(int默认就是signed int). 三者都占1个字节( ...

  6. mysql 结合keepalived测试

    vip:192.168.32.66 192.168.32.6 主库: mysql> show variables like '%read_only%'; +------------------+ ...

  7. 【虚拟化实战】容灾设计之一VR vs SRM

    作者:范军 (Frank Fan) 新浪微博:@frankfan7 从本文开始,我们将介绍一系列的关于容灾的解决方案.先探讨应用的场景,然后再深入介绍技术架构. 情景一: 某小型公司的虚拟化环境中,在 ...

  8. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  9. Eclipse用法和技巧十一:分栏显示

    在编码的时候,有时候需要同时看到两个文件的代码.或者在代码走读的时候,能同时看到两个文件的代码能加快我们对代码的理解.来看看如何在eclipse中同时显示两个文件的代码.        步骤一:拖住一 ...

  10. iframe间的通信

    父框架 <body></body> <script type="text/javascript"> document.domain = '100 ...