poj 3262 Protecting the Flowers(贪心)

来源:互联网 发布:java 视频监控系统 编辑:程序博客网 时间:2024/05/17 09:09

题意:

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

注意大数陷阱

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct In{int x,y;}; In cows[100010];int cmp(In a,In b){return a.y*1.0/a.x>b.y*1.0/b.x;}int main(){int n,m,i,j;long long s,t;while(~scanf("%d",&n)){memset(cows,0,sizeof(cows));for(i=0;i<n;i++){scanf("%d%d",&cows[i].x,&cows[i].y);}sort(cows,cows+n,cmp);//s=cows[0].y,t=cows[0].x*2;for(s=t=i=0;i<n;i++){s+=t*cows[i].y;t+=cows[i].x*2;}printf("%lld\n",s);}return 0;}



0 0