USACO2007 Protecting the Flowers /// 比值 前缀和 oj21161
题目大意:
有N (2 ≤ N ≤ 100,000) 头牛偷吃花
将牛赶回牛棚需Ti minutes (1 ≤ Ti ≤ 2,000,000)
每头牛每分钟能吃Di (1 ≤ Di ≤ 100) 朵花
则赶牛的来回需2*Ti minutes (Ti to get there and Ti to return)
* Line 1: A single integer N
* Lines 2..N+1: Each line contains two space-separated integers, Ti and Di, that describe a single cow's characteristics
* Line 1: A single integer that is the minimum number of destroyed flowers
6
3 1
2 5
2 3
3 2
4 1
1 6
86
一开始用DFS 结果TLE
#include <bits/stdc++.h>
using namespace std;
long long n,ans,sum;
struct cow
{
double t,f,s;
}a[];
bool cmp(struct cow a,struct cow b)
{
return a.s>b.s;
}
int main()
{
scanf("%lld",&n);
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&a[i].t,&a[i].f);
a[i].s=a[i].f/a[i].t; ///s为每分钟吃花的数量与赶牛时间的比值
选取耗时少且吃花多的牛能最大限度地减少损失 则应先赶s更大的牛
sum+=a[i].f; ///利用前缀和 省略每次重新循环计量的浪费
}
sort(a+,a++n,cmp);
for(int i=;i<=n;i++)
{
sum-=a[i].f;
ans+=a[i].t*sum*;
}
printf("%lld\n",ans); return ;
}
USACO2007 Protecting the Flowers /// 比值 前缀和 oj21161的更多相关文章
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 448 So ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 493 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朵 ...
- 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...
- POJ 3262 Protecting the Flowers 贪心(性价比)
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7812 Accepted: ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...
随机推荐
- Java的poi技术遍历Excel时进行空Cell,空row,判断
/** * 导入信息 */ @Override public List<Object> add(HttpServletRequest request) { // TODO Auto-gen ...
- web跨域问题解决方案
在前端开发及调试过程中总能遇到浏览器报如下错误: Response to preflight request doesn't pass access control check: No 'Access ...
- Neo4j原生语句cc
Cypher语句 Cypher语句是Neo4j的图查询语言.以下例子来自Neo4j Browser,启动后在命令栏输入:play cypher即可1. 创建一个节点: 语法:CREATE (node- ...
- (转)VS2015基础 指定一个或多个项目执行 - 心少朴的博客
慈心积善融学习,技术愿为有情学.善心速造多好事,前人栽树后乘凉.我今于此写经验,愿见文者得启发. 这个解决方案下,有两个项目, 看到黑体的project了吗?它就是指定执行的项目. 这两 ...
- Linux初始化的汇编代码
1. 内核文件布局 首先看一下arch/x86/boot/Setup.ld文件,它定义了链接后的内核文件布局. 1: /* 2: * setup.ld 3: * 4: * Linker script ...
- MySQL数据库(五)—— 用户管理、pymysql模块
用户权限管理.pymysql模块 一.用户管理(权限管理) 在MySQL中自带的mysql数据库中有4个表用于用户管理的 # 优先级从高到低 user > db > tables_priv ...
- Java各版本的含义
JavaSE(Java Standard Edition):标准版,定位在个人计算机上的应用.这个版本是Java平台的核心,它提供了非常丰富的API来开发一般个人计算机上的应用程序,包括用户界面接口A ...
- linux学习的任督二脉-进程调度和内存管理
转自 宋宝华老师的博客原文:https://blog.csdn.net/21cnbao/article/details/77505330 内功心法 学习或遇到问题时,反过来主动思考如果我是设计者,我会 ...
- Oracle导出存储过程对象
$ pwd/home/oracle 导出存储过程 $ vi test.par INCLUDE=PROCEDURE:"IN ('P_TEST_LAST_DDL')" SCHEMAS= ...
- css垂直居中设置
转载自大佬的文章:纯css实现垂直居中的几种方法(https://www.cnblogs.com/hutuzhu/p/4450850.html) 总结得很棒,有好几种方法自己没用过的,拷贝过来给自己看 ...