HDU 4296
来源:互联网 发布:网络数据抓取 编辑:程序博客网 时间:2024/06/07 17:12
看了别人的报告才写出来的
证明:对于相邻放置的两块板,设两块板为i,j他们上面的重量为sum
1) a=sum-si;b=sum+wi-sj;
交换两个板的位置
2)a'=sum+wj-si;b'=sum-sj;
如果1优于2,求解得有效的条件为wj-si>wi-sj。
所以按si+wi的和排序贪心即可。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long longstruct point{ int w,s;}node[100005];int n;bool cmp(const point &a,const point &b){ return a.w+a.s<b.w+b.s;}int main(){ for(;~scanf("%d",&n);) { for(int i=0;i<n;++i) scanf("%d%d",&node[i].w,&node[i].s); sort(node,node+n,cmp); LL summ=0,maxx=0; for(int i=0;i<n;++i) { maxx=max(maxx,summ-node[i].s); summ+=node[i].w; } printf("%I64d\n",maxx); } return 0;}
- hdu 4296
- HDU 4296
- [hdu] 4296 Buildings
- HDU 4296 Buildings
- HDU 4296 Buildings
- hdu 4296 Buildings
- hdu - 4296 - Buildings
- HDU 4296 buildings
- hdu 4296(buildings)
- hdu 4296 Building
- hdu 4296(贪心)
- hdu-4296-Buildings
- HDU 4296 Buildings(贪心)
- HDU-4296-Buildings
- hdu 4296 贪心
- hdu 4296 贪心
- hdu 4296 Buildings(贪心)
- HDU 4296 Buildings
- 网络安全学习
- 《Unix环境高级编程》:线程和fork
- 解决编辑时combobox显示编号而不是文本的问题
- 计算机义诊--山东大学(威海)CSDN俱乐部与软爱合办
- http://xheditor.com/
- HDU 4296
- Python SMTP 发送带附件电子邮件
- c# 多线程下载文件
- 母亲的唠叨
- ubutun下安装mysql
- 不借助第三个变量来交换两个变量的值
- 棋盘覆盖问题
- 浅谈ado.net 五大对象
- 简单的的SimpleTron(C语言实现,程序内部实现体验)