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 ...
随机推荐
- DotNet命名规范参考(转)
来自:http://www.cnblogs.com/w-y-f/archive/2012/05/30/2526254.html DotNet命名规范参考 一.命名规范 注意事项:使用英文命名规则,尽量 ...
- windows phone7开发环境配置错误
遇到下面这样一个问题:在配置windows phoe7开发环境的时候出现如下错误,以及相应的解决方案,希望对大家有所帮助. 装完环境后出现下面错误: [caption id="attachm ...
- Solr部署详解
Solr部署详解 时间:2013-11-24 方式:转载 目录 1 solr概述 1.1 solr的简介 1.2 solr的特点 2 Solr安装 2.1 安装JDK 2.2 安装Tomcat 2.3 ...
- boost/lexical_cast.hpp的简单使用方法_行动_新浪博客
boost/lexical_cast.hpp的简单使用方法_行动_新浪博客 boost/lexical_cast.hpp的简单使用方法 (2010-03-19 16:31:13) ...
- MySQL如何查询LINESTRING数据
我有一个提交的命名crm_geo_org,具有以下结构 ipoid INTEGER 11 NOT NULL PRIMARY KEY beginip INTEGER 14 NOT NULL UNSIGN ...
- ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected解决方法
在进行物理主备库角色转换的时候遇到ORA-01093错误 SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY; ALTER ...
- ajax跨域请求--jsonp实例
ajax请求代码: //区域事件选择配送点 function changeDistrict(value){ if(value == 0){ $('#transport_node').empty(); ...
- eclipse的SVN插件的配置
http://www.cnblogs.com/kekec/archive/2010/08/09/1795581.html
- itextSharp 使用模板(PdfTemplate)不规则分栏(ColumnText)
public static void Main() { Document document = new Document(); BaseFont bf = BaseFont.createFont(Ba ...
- Windows下用WinSCP传输数据到Linux上
Scenario:最近公司做的一个项目,UI部分我是使用python在编译时做localization的,是linux下运行的,但是开发是在windows下进行的每次编译后都要手动通过WinSCP这个 ...