题目大意:

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)

Input

* 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

Output

* Line 1: A single integer that is the minimum number of destroyed flowers

Sample Input

6
3 1
2 5
2 3
3 2
4 1
1 6

Sample Output

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的更多相关文章

  1. BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 448  So ...

  2. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

  3. 1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 493  So ...

  4. [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 885  So ...

  5. [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心

    Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...

  6. 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...

  7. POJ 3262 Protecting the Flowers 贪心(性价比)

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7812   Accepted: ...

  8. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  9. bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...

随机推荐

  1. share memory

    header for public argument:shmdata.h #define TEXT_SZ 2048 struct shared_use_st { int written; char t ...

  2. Java-Class-C:com.github.pagehelper.PageHelper

    ylbtech-Java-Class-C:com.github.pagehelper.PageHelper 1.返回顶部   2.返回顶部 1.1. import com.github.pagehel ...

  3. 【mac】配置sublime开发C

    1.sublime text3,Tools/Build System/New Build system创建一个新配置文件. {"cmd": ["gcc", &q ...

  4. python中的缓存技术

    python缓存技术 def console(a,b): print('进入函数') return (a,b) print(console(3,'a')) print(console(2,'b')) ...

  5. 监控数据库SqlServer

    监控数据库的连接数select COUNT( * ) from master.dbo.sysprocesses select COUNT( * ) from master.dbo.sysprocess ...

  6. 装箱与拆箱(TDB)

    装箱:把值类型转换为引用类型 拆箱:把引用类型转换为值类型 只能对之前装箱的变量进行拆箱.需要强制转换.

  7. 使用sublime+platUML快速画流程图

    程序员难免要经常画流程图,状态图,时序图等.以前经常用 visio 画,经常为矩形画多大,摆放在哪等问题费脑筋.有时候修改文字后,为了较好的显示效果不得不再去修改图形.今天介绍的工具是如何使用 Sub ...

  8. struts2类型转换1

    概述 从一个 HTML 表单到一个 Action 对象, 类型转换是从字符串到非字符串. HTTP 没有 “类型” 的概念. 每一项表单输入只可能是一个字符串或一个字符串数组. 在服务器端, 必须把 ...

  9. 数组foreach

    简单使用 代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  10. shell脚本中关于日期的操作

    一.计算指定日期的前一天的日期 date -d "yesterday 20150401 " +%Y%m%d 二.如果获取当前日期的前一天        date -d " ...