bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花【贪心】
2018-05-02 22:00
429 查看
因为交换相邻两头牛对其他牛没有影响,所以可以通过交换相邻两头来使答案变小。按照a.t*b.f排降序,模拟着计算答案
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=100005; int n; long long ans,sum; struct qwe { int v,t; }a ; bool cmp(const qwe &a,const qwe &b) { return (double)a.v/a.t>=(double)b.v/b.t; } int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<'0') { if(p=='-') f=-1; p=getchar(); } while(p>='0'&&p<='9') { r=r*10+p-48; p=getchar(); } return r*f; } int main() { n=read(); for(int i=1;i<=n;i++) a[i].t=read()*2,a[i].v=read(),sum+=a[i].v; sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) { sum-=a[i].v; ans+=sum*a[i].t; } printf("%lld\n",ans); return 0; }
相关文章推荐
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
- [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
- 【BZOJ】1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心)
- 【bzoj1634】[Usaco2007 Jan]Protecting the Flowers 护花 贪心
- [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心
- |BZOJ 1634|贪心|[Usaco2007 Jan]Protecting the Flowers 护花
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- [BZOJ1634] [Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ 1634 [Usaco2007 Jan]Protecting the Flowers 护花
- [BZOJ] 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
- bzoj1634[Usaco2007 Jan]Protecting the Flowers 护花
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ [Usaco2007 Jan]Protecting the Flowers 护花(隐藏题)
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花