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朵 ...
随机推荐
- opencv3在CMakeLists.txt中的调用问题
在cmake工程中使用opencv需要在CMakeLists.txt文件中加以调用,在opencv2.xx版本,可以用以下语句 # 寻找OpenCV库 find_package( OpenCV REQ ...
- HDU 2544 - 最短路 - [堆优化dijkstra][最短路模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 Time Limit: 5000/1000 MS (Java/Others) Memory Li ...
- IDEA2016.3搭建Struts2+Hibernate+Spring项目环境
IDEA搭建SSH环境 1.环境 软件版本:IntelliJ IDEA 2016.3.2 系统:windows 7 32位 / ubuntu 框架:Hibernate3,Spring3.2, Stru ...
- MTD 移动目标防御技术
移动目标防御技术,主要包括系统随机化,生物启发MTD,网络随机化,云MTD,动态编译等等.研讨会还就威胁建模和量化移动目标防御技术的效能评估进行了推进.理论和定量的模型对于该技术的颠覆性影响至关重要. ...
- kafka杂记
对kafka介绍全面的一个链接 [传送门]http://blog.csdn.net/lizhitao/article/details/39499283 http://blog.csdn.net/liz ...
- Mybatis插入数据后返回主键id
有时候使用mybatis插入数据后,需要用到记录在数据库中的自增id,可以利用keyProperty来返回,赋值给实体类中的指定字段. 单条记录插入并返回 First, if your databas ...
- Stringbuffer扩容
public class A { public static void main(String[] args) { StringBuffer ab=new StringBuffer(); String ...
- Core Data with Mantle
Mantle makes it easy to write a simple model layer for your Cocoa or Cocoa Touch application. Mantl ...
- spring boot配置service发布服务
在application.yml中配置 server: port: 8080 context-path: /crm spring: datasource: driver-class-name: com ...
- [git]git版本管理学习记录
今天看到别人用这玩意记录自己的进度, 我也学习了一下. 1,适当的工具会提升效率 2,关注点还是得放在代码本身上. github/gitignore github提供了各种gitignore文件 有p ...