bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers
难得的信息课......来一题水题吧。
经典贪心题
我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并没有影响。
我们设距离为$a_{i}$,每分钟贡献$b_{i}$
$a_{1}$ $b_{1}$
$a_{2}$ $b_{2}$
先抓第一头的代价:$a_{1}b_{1}+2a_{1}b_{2}+a_{2}b_{2}$
先抓第二头的代价:$a_{2}b_{2}+2a_{2}b_{1}+a_{1}b_{1}$
显然,我们按照$a_{1}b_{2}<a_{2}b_{1}$的顺序排序,蓝后贪心就行了
注意在决定抓某只奶牛时它就已经不能吃花了
退役后做题,内心有好多感慨......然鹅没时间写了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct data{
int a,b;
bool operator < (const data &tmp) const{
return a*tmp.b<b*tmp.a;//a1*b2<a2*b1
}
}c[];
int n; long long ans,ti;
int main(){
scanf("%d",&n);
for(int i=;i<=n;++i)
scanf("%d%d",&c[i].a,&c[i].b);
sort(c+,c+n+);
for(int i=;i<=n;++i)
ans=ans+ti*c[i].b,ti+=c[i].a*;
printf("%lld",ans);
return ;
}
bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers的更多相关文章
- 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...
- 洛谷P2878 [USACO07JAN]保护花朵Protecting the Flowers
题目描述 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. ...
- P2878 [USACO07JAN]保护花朵Protecting the Flowers
一个类似国王游戏的贪心 话说要是先做了这个题,国王游戏之余懵逼这么久吗? #include<iostream> #include<cstdio> #include<alg ...
- Luogu_2878_[USACO07JAN]保护花朵Protecting the Flowers
题目描述 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. ...
- USACO 保护花朵 Protecting the Flowers, 2007 Jan
Description 约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的.他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草.可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园 ...
- USACO Protecting the Flowers
洛谷 P2878 [USACO07JAN]保护花朵Protecting the Flowers 洛谷传送门 JDOJ 1009: 护花 JDOJ传送门 Description FJ出去砍木材去了,把N ...
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 448 So ...
- [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 885 So ...
- [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...
随机推荐
- XCache 一种快速可靠的PHP操作码缓存
1,错误报告开启 错误报告是在PHP中一个非常有用的功能,应同时在开发阶段启用. 这可以帮助我们确定我们的代码中的问题. 最常用的功能是“E_ALL”,这有助于我们发现所有的警告和严重错误. 必须指出 ...
- CentOS6.5安装配置PPTP
本次安装环境为Ucloud云服务器 1,操作系统版本检查 2,安装ppp,pptp yum install -y ppp rpm -ivh http://static.ucloud.cn/pptpd- ...
- 专访|HPE测试中心总监徐盛:测试新思维-DevOps,持续测试,更敏捷,更快速
2016年7月22日,「HPE&msup软件技术开放日」将在上海浦东新区,张江高科技园区纳贤路799号科荣大厦小楼2楼举办,msup携手HPE揭秘全球测试中心背后的12条技术实践. 徐盛:HP ...
- IDEA2016.3搭建Struts2+Hibernate+Spring项目环境
IDEA搭建SSH环境 1.环境 软件版本:IntelliJ IDEA 2016.3.2 系统:windows 7 32位 / ubuntu 框架:Hibernate3,Spring3.2, Stru ...
- gis 相关资料
--gis原理学习 http://group.cnblogs.com/GIS/best-1.html http://www.cnblogs.com/SuperXJ/tag/移动GIS/ --gis坐标 ...
- CCCC 月饼
https://www.patest.cn/contests/gplt/L2-003 题解:按平均值贪心. 坑:有一个样例卡住了,是因为 while (i<=n&&x - bs[ ...
- 英特尔和 Google 的 OKR 制度与我们一般所说的 KPI 有什么不同?
英特尔和 Google 的 OKR 制度与我们一般所说的 KPI 有什么不同? - 知乎 https://www.zhihu.com/question/22478049?sort=created 知乎 ...
- mySql的普通索引和复合索引
有关普通索引和组合索引问题: 索引分单列索引和组合索引:单列索引,即一个索引只包含单个列,一个表可以有多个单列索引,但这不是组合索引:组合索引,即一个索包含多个列. MySQL索引类型包括: ...
- 洛谷P2657 windy数 [SCOI2009] 数位dp
正解:数位dp 解题报告: 传送门! 这题一看就是个数位dp鸭,"不含前导零且相邻两个数字之差至少为2"这种的 然后就直接套板子鸭(板子戳总结,懒得放链接辣QAQ 然后就是套路 然 ...
- vue学习之五生命周期
一.vue生命周期图解 下图展示了实例的生命周期.你不需要立马弄明白所有的东西,不过随着你的不断学习和使用,它的参考价值会越来越高. 二.vue钩子函数使用 2.1beforeCreate 在实例初始 ...