POJ-3045-Cow Acrobats
来源:互联网 发布:淄博专门做seo的公司 编辑:程序博客网 时间:2024/05/17 09:02
写出式子,风险值就应该等于W总-Wnow-Snow,那么就应该为W总-(Wnow+Snow),然后可以看出要值最小,那么Wnow+Snow应该最大,所以按这个进行排序,然后最大的放最下面即可
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int inf=1<<29;const int maxn=5e4+100;struct Cow{ int w; int s; bool operator < (const Cow &a)const { return w+s<a.w+a.s; }}a[maxn];int n;long long sum;int main(){ while(scanf("%d",&n)!=EOF) { sum=0; for(int i=0;i<n;i++) { scanf("%d%d",&a[i].w,&a[i].s); sum+=a[i].w; } sort(a,a+n); long long ans=-inf; for(int i=n-1;i>=0;i--) { sum-=a[i].w; ans=max(ans,sum-a[i].s); } printf("%I64d\n",ans); } return 0;}
0 0
- poj-3045 Cow Acrobats
- POJ 3045 Cow Acrobats
- POJ 3045-Cow Acrobats
- POJ-3045-Cow Acrobats
- POJ 3045 Cow Acrobats
- poj 3045 Cow Acrobats
- POJ 3045 Cow Acrobats
- poj 3045 Cow Acrobats
- POJ-3045Cow Acrobats
- poj 3045 Cow Acrobats
- Cow Acrobats - POJ 3045 排序
- POJ 3045 Cow Acrobats 贪心
- poj 3045 Cow Acrobats(数学题)
- poj 3045 Cow Acrobats 贪心
- POJ 3045 - Cow Acrobats(贪心)
- POJ - 3045 Cow Acrobats 贪心
- poj 3045 Cow Acrobats 贪心
- poj 3045 Cow Acrobats 【二分】
- 全自动过滤器:全自动自清洗过滤器对给排水总结的经验
- C++ 重载运算符“=”检测自赋值
- poj 1005
- 划分树模板题
- 从Borland C++了解的
- POJ-3045-Cow Acrobats
- 母函数系列之Fruit hdoj 2152
- SQL中DATEDIFF和DATEPART的用法
- 【MFC】BROWSEINFO 设置路径并显示
- Android之GPS定位类 LocationManager、LocationListener、GpsStatus.Listener、Location详解
- 太难了》》》》
- 选好理财方式、让您的家庭更加温馨
- 基础代码--物体向手指滑向的方向移动
- 关于VS的MFC应用程序向导