poj 3262 Protecting the Flowers (贪心)

来源:互联网 发布:数据库中的模式 编辑:程序博客网 时间:2024/05/01 03:48

题意:

有n个牛在FJ的花园乱吃。

所以FJ要赶他们回牛棚。

每个牛在被赶走之前每秒吃Di个花朵。赶它回去FJ要花的时间是Ti。在被赶走的过程中牛就不能乱吃了


分析:

1、优先赶吃单位时间内吃花快的牛。

2、注意大数陷阱。


#include<cstdio>#include<algorithm>using namespace std;struct node{    int t,d;}cow[100010];bool cmp(node x,node y){    return x.d*y.t > x.t*y.d;}int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=0;i<n;i++)            scanf("%d%d",&cow[i].t,&cow[i].d);        sort(cow,cow+n,cmp);        long long ans=0;        int tt=0;        for(int i=0;i<n;i++)        {            ans+=cow[i].d*tt;            tt+=cow[i].t*2;        }        printf("%lld\n",ans);    }    return 0;}



0 0
原创粉丝点击