網頁

2014年1月2日 星期四

POJ 3262 Protecting the Flowers

這題與UVa 10026 Shoemaker's Problem是一樣的


#include<cstdio>
#include<algorithm>
using namespace std;
struct cow{
int T;
int D;
};
bool cmp(cow a,cow b)
{
return (a.D*1.0/a.T)>(b.D*1.0/b.T); //*1.0
}
int main()
{
int N,i,j;
long long sum=0,ans=0; //long long int
cow a[100001];
while(scanf("%d",&N)!=EOF){
for (i=0;i<N;i++){
scanf("%d%d",&a[i].T,&a[i].D);
sum+=a[i].D;
}
sort(a,a+N,cmp);
for(i=0;i<N;i++){
sum-=a[i].D;
ans+=(sum*2*a[i].T);
}
printf("%lld\n",ans);
}
return 0;
}

沒有留言:

張貼留言