博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ 1634. [Usaco2007 Jan]Protecting the Flowers 护花
阅读量:4693 次
发布时间:2019-06-09

本文共 755 字,大约阅读时间需要 2 分钟。

考虑任意一个运送顺序,对于第 $i$ 头牛和第 $j=i+1$ 头牛,把它们的顺序交换会如何

首先其他牛的代价仍然不变

改变的代价为 $2t[i]*v[j]-2t[j]*v[i]$,如果左边式子小于 $0$,我们就把这两头牛交换,一直交换最终代价就是最小的

所以直接按 $t[i]/v[i]$ 排序就好了,$cmp$ 函数可以写成 $t[i]*v[j]<t[j]*v[i]$

#include
#include
#include
#include
#include
using namespace std;typedef long long ll;inline int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f;}const int N=2e5+7;int n;struct dat{ int x,y; inline bool operator < (const dat &tmp) const { return x*tmp.y

 

转载于:https://www.cnblogs.com/LLTYYC/p/11367940.html

你可能感兴趣的文章
六、雪花《苹果iOS实例编程入门教程》
查看>>
单页面应用(SPA)
查看>>
mahout 安装
查看>>
Application,Session和Cookie
查看>>
sql中的系统表sysobjects以及如何查看sql语句的执行时间
查看>>
Git的使用
查看>>
Redis Python开发指南
查看>>
4.如果给一个单位做相关的软件,你认为最重要的是需要得到谁的支持,为什么?...
查看>>
视图基本
查看>>
提高Java代码质量的Eclipse插件之Checkstyle的使用具体解释
查看>>
【莫比乌斯反演】——蒟蒻的理解
查看>>
ORM系列之二:EF(4) 约定、注释、Fluent API
查看>>
cnblogs latex公式
查看>>
js中的替换
查看>>
SKTextureAtlas类
查看>>
自己写的网页放在github里面
查看>>
关于Git的学习
查看>>
nginx proxy文件编写总结
查看>>
决策树应用
查看>>
LightOJ_1248 Dice (III)
查看>>