UVA 1467 Installations(贪心)
来源:互联网 发布:淘宝返利网都有哪些 编辑:程序博客网 时间:2024/05/21 19:35
思路:点击打开链接
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=1000+10;struct node{ int s,d;}ti[maxn];int n,p;int cmp(node a,node b){ return a.d<b.d;}int deal(int x){ int sum=0,a=0,b=0; for(int i=0;i<=p;i++) { if(i==x) continue; sum+=ti[i].s; int temp=max(sum-ti[i].d,0); if(temp>a){ b=a; a=temp; } else if(temp>b){ b=temp; } } sum+=ti[x].s; int temp=max(sum-ti[x].d,0); if(temp>a){ b=a; a=temp; } else if(temp>b){ b=temp; } return a+b;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&ti[i].s,&ti[i].d); sort(ti,ti+n,cmp); int sum=0,a=0,b=0; for(int i=0;i<n;i++) { sum+=ti[i].s; int temp=max(sum-ti[i].d,0); if(temp>a) { b=a; a=temp; p=i; } else if(temp>b) { b=temp; p=i; } } int ans=a+b; for(int i=0;i<p;i++) ans=min(ans,deal(i)); printf("%d\n",ans); } return 0;}
0 0
- UVA 1467 Installations(贪心)
- UVA 1467 - Installations(贪心)
- uva 1467 - Installations( 贪心+暴力)
- UVa 1467 Installations 解题报告(贪心)
- Uva-1467-Installations
- LA 4850 Installations (贪心)
- LA 4850 Installations 贪心 *
- ACM: uva 1467 - Installations
- UVALive - 4850 Installations 贪心+枚举
- Installations
- Radar Installations
- Windows Installations
- UVA1467 - Installations
- LA4850 - Installations
- uva 11389(贪心)
- Uva 11100(贪心)
- uva 1388 - Graveyard(贪心)
- UVA 10037 - Bridge(贪心)
- hdu 1325 Is It A Tree?(并查集)
- VS2010 运行速度加快方法
- windows 声音处理
- onCreat() 方法
- C++11新特性
- UVA 1467 Installations(贪心)
- sizeof与strlen的区别
- VS2010调试极慢,因为启动了IntelliTrace
- 微信小程序开发思路
- ajax配合struts2(ssh2)实现无刷新验证用户名是否唯一
- android The method of type must override a superclass method
- 分析android程序项目结构
- 1. Two Sum
- 快速排序法-java实现