*Protecting the Flowers(POJ 3262, 贪心)

来源:互联网 发布:windows桌面图标分类 编辑:程序博客网 时间:2024/05/17 22:04

题目链接

       题目大意:牛在花园里吃花,牛i每分钟吃花Di,牵走牛i再回来的时间为2Ti,求最小损失花数。

#include<cstdio>#include<algorithm>using namespace std;const int MAX_N = 100005;struct cow {int T, D;} a[MAX_N];int N, rest_D;long long ans;bool cmp(cow b, cow c){return b.T*c.D < c.T*b.D;}void init(){rest_D = 0;for(int i=0; i<N; i++){scanf("%d%d", &a[i].T, &a[i].D);rest_D += a[i].D;}ans = 0;}void f(){for(int i=0; i<N; i++){rest_D -= a[i].D;ans += 2 * a[i].T * rest_D;}}int main(){while(~scanf("%d", &N)){init();sort(a, a+N, cmp);f();printf("%lld", ans);}return 0;}


原创粉丝点击