hdu 4296(buildings)
来源:互联网 发布:stc单片机串口程序 编辑:程序博客网 时间:2024/04/28 11:09
题目链接:点击打开链接
题目分析:贪心算法+轮换对称 ,a:wi,si;b:wj,sj;
对于a在b上:pda:wi-sj
b在a上:wj-si;
当a优于b时;wi-sj>wj-si wi+si>wj+wj
#include<cstdio> #include<cstdlib> #include<algorithm> #include<algorithm> using namespace std; struct data{ int weight; int strenth; }; data info[100010]; int cmp( data a,data b) { return (a.weight+a.strenth)<(b.weight+b.strenth); } int main() { int n,i,w,s; __int64 ans,temp,sum; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%d %d",&info[i].weight,&info[i].strenth); sort(info,info+n,cmp); ans=info[0].weight-info[1].strenth; sum=info[0].weight; for(i=1;i<n-1;i++) { sum+=info[i].weight; temp=sum-info[i+1].strenth; if(ans<temp) ans=temp; } if(ans<=0) ans=0; if(n==1) printf("0\n"); else printf("%I64d\n",ans); } return 0; }
- hdu 4296(buildings)
- HDU 4296 Buildings(贪心)
- HDU 4296 Buildings (YY)
- hdu 4296 Buildings(贪心)
- [hdu] 4296 Buildings
- HDU 4296 Buildings
- HDU 4296 Buildings
- hdu 4296 Buildings
- hdu - 4296 - Buildings
- HDU 4296 buildings
- hdu-4296-Buildings
- HDU 4296 Buildings(贪心)
- HDU-4296-Buildings
- hdu 4296 Buildings(贪心)
- HDU 4296 Buildings
- 贪心-- HDU - 4296 Buildings
- hdu 4296 Buildings
- hdu 4296 Buildings
- Proftpd INSTALL翻译(Troubleshoot和Help部分没有翻译)
- VMware vSphere 5.5的12个更新亮点(2)
- awk内置函数
- windows下Android源码的分模块下载
- VMware vSphere 5.5的12个更新亮点(3)
- hdu 4296(buildings)
- private, protected, public快速理解
- Android-----WebView使用
- 1179. Extrusion
- 数学之路(3)-机器学习(3)-机器学习算法-神经网络[20]
- 菜谱
- windows下如何用wireshark抓本地回路抓包
- Concurrency Runtime微软的并发运行时机制
- 处理器、CPU、核的区别