HDU 4296 Buildings (YY)
题意: 给定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)的更多相关文章
- hdu 4296 Buildings(贪婪)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others ...
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5734 Acperience(返虚入浑)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5724 Chess(国际象棋)
HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 5826 physics(物理)
physics(物理) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) D ...
- HDU 5835 Danganronpa(弹丸论破)
Danganronpa(弹丸论破) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ)
HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU 5976 Detachment(拆分)
HDU 5976 Detachment(拆分) 00 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem D ...
- HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spheric ...
随机推荐
- Ubuntu下编译Android JNI最靠谱的方法...
网上资料太杂乱,搞了大半天都还是没搞懂怎么系统的调用NDK.最后干脆放弃了Win改用Ubuntu编译JNI,虽然编译环境简单了,但是资料却少了不少.几乎没有一篇完整的文章.我想或许是能在Ubuntu下 ...
- JAVA学习第三十六课(经常使用对象API)— Set集合:HashSet集合演示
随着Java学习的深入,感觉大一时搞了一年的ACM,简直是明智之举,Java里非常多数据结构.算法类的东西,理解起来就轻松多了 Set集合下有两大子类开发经常使用 HashSet集合 .TreeSet ...
- Adobe Acrobat Ⅺ Pro安装激活
1.注意一定要断网安装,如果你有防火墙拦截亦可(注意:系统自带那防火墙不行). 2.将AcrobatPro_11_Web_WWMUI.exe解压到一个目录下,找到目录下的setup.exe安装,安装时 ...
- WOJ 1014
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { double a[3][3]= ...
- 小胖说事24-----property's synthesized getter follows Cocoa naming convention for returning 'owned' objec
今天在给类的属性命名的时候,用了newValue.就给报错:property's synthesized getter follows Cocoa naming convention for retu ...
- Linux OpenCV读取视频失败,cvCreateFileCapture失败的解决
背景: 近期想在嵌入式平台上开发QT+Opencv,无料PC机上编写的OpenCV程序老是打不开视频. 開始提示:OpenCV Error: Bad argument (Array should be ...
- NEC协议
注意: 用示波器在接收头抓的电平看起来和NEC协议刚好相反, 那是因为:HS0038B 这个红外一体化接收头,当收到有载波的信号的时候,会输出一个低电平,空闲的时候会输出高电平. 具体情况,具体分析. ...
- 网盘大全, 邮箱大全 good
网盘推荐 115网盘 注册 百度网盘 注册 微云 注册 360云盘 注册 金山快盘 注册 新浪微盘 注册 和彩云 注册 酷盘 注册 OneDrive 外链 BOX 注册 Dropbox 注册 国内网盘 ...
- WCF技术剖析之十八:消息契约(Message Contract)和基于消息契约的序列化
原文:WCF技术剖析之十八:消息契约(Message Contract)和基于消息契约的序列化 [爱心链接:拯救一个25岁身患急性白血病的女孩[内有苏州电视台经济频道<天天山海经>为此录制 ...
- git clone cm source & cm vs android version
$ git clone https://github.com/CyanogenMod/android_packages_apps_DeskClock.git -b cm-9.0.0 CM4代表(And ...