标签:space lin node nod bsp include get bool 最大
其实这题不难,只是想告诉自己:贪心不全是真的脑残拿最大就AC
此题实际上就是比较x,y优先级利用时间计算得到a[i]t/a[i].d(没错时间在上,并非惯性思维的d在上)
t*a[x].d+(t+a[x]*t)*a[y].d<=t*a[y].d+(t+a[y].t)*a[x].d分别比较不同顺序带给两者的花费
#include<bits/stdc++.h> #define rep(i,x,y) for(register int i=x;i<=y;i++) #define LL long long using namespace std; const int N=100500; int n;LL ans,now; inline int read(){ int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch==‘-‘)f=-1;ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x*f;}struct node{int t,d;double k;}a[N]; bool cmp(node a,node b){return a.k<b.k;}int main(){ n=read();rep(i,1,n) a[i].t=read()*2,a[i].d=read(),a[i].k=(double)a[i].t/a[i].d; sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) ans+=now*a[i].d,now+=a[i].t; printf("%lld",ans);return 0;}
标签:space lin node nod bsp include get bool 最大
原文地址:https://www.cnblogs.com/asdic/p/9668942.html