首页 > 其他 > 详细

Protecting the flowers 贪心

时间:2021-06-03 10:30:59      阅读:26      评论:0      收藏:0      [点我收藏+]

题目:

https://ac.nowcoder.com/acm/problem/25043

//思路:需要推出贪心的式子,后面的和接水一个原理

#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=1e5+7;
struct no
{
int d,t;
};
int cmp(no a,no b)
{
return a.t*b.d<a.d*b.t;
}
int main()
{struct no n[maxn];
int q;
scanf("%d",&q);
for(int i=0;i<q;i++)
scanf("%d %d",&n[i].t,&n[i].d);
sort(n,n+q,cmp);
long long sum=0;
long long ans=0;
for(int i=0;i<q;i++)
{ ans+=sum*n[i].d;
sum+=n[i].t;
}
printf("%lld\n",2*ans);
}

Protecting the flowers 贪心

原文:https://www.cnblogs.com/aacm/p/14843563.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!