标签:node pre 循环 usaco lan typedef cti signed protect
随便搞一搞就好了
贪心+排序
对于牛的排序:a.t * b.d<a.d * b.t (手动推一推就好了)
读入的时候,将所有牛每分钟所吃的花数总和统计起来,然后循环中按照顺序,先把当前所要运走的牛吃花的数量减去,然后用剩下的花的总数乘上所要运走的牛的时间t*2(往返两次)
#include<bits/stdc++.h>
typedef unsigned long long ll;
using namespace std;
const int maxn=1e5+10;
int n;
struct node{
int t,d;
}e[maxn];
bool cmp(node a,node b){return a.t*b.d<a.d*b.t;}
ll sum,ans;
int main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>e[i].t>>e[i].d,sum+=e[i].d;
sort(e+1,e+n+1,cmp);
for(int i=1;i<=n;i++){
sum-=e[i].d;
ans+=sum*(e[i].t*2);
}
printf("%lld",ans);
return 0;
}
代码还是挺清爽的呀!
[USACO07JAN]Protecting the Flowers S
标签:node pre 循环 usaco lan typedef cti signed protect
原文地址:https://www.cnblogs.com/qzwer/p/12989734.html