题目大意:

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. java lambda filter写法

    datas.stream().filter(m->!m.getSerialId().equals(setting.getSerialId())).collect(Collectors.toLis ...

  2. 前端(十二)—— JavaScript基础操作:if语句、for循环、while循环、for...in、for...of、异常处理、函数、事件、JS选择器、JS操作页面样式

    JavaScript基础操作 一.分支结构 1.if语句 if 基础语法 if (条件表达式) { 代码块; } // 当条件表达式结果为true,会执行代码块:反之不执行 // 条件表达式可以为普通 ...

  3. Day 18 :面向对象[基础,继承,组合]类的增删改查

    有的人说,编程有3种范式: 1.面向过程:就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用就可以了. 2.面向函数:面向函数是面向过程的升级版,也就是把每个 ...

  4. maven管理工具配置

    1.登录maven.apache.org,下载maven.,选择apache-maven-3.6.2-bin.zip,并解压到所需目录. 2.进行环境配置,计算机右击--属性---高级系统配置---环 ...

  5. ArcGis面要素空间连接,取相交面积最大者 C#

    核心代码: #region JoinWork_IntersectMax private void CreateNewFields_IntersectMax(IFeatureClass destFeat ...

  6. (转)Java中Image的水平翻转、缩放与自由旋转操作

    来自:http://cping1982.blog.51cto.com/601635/130066/ 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责 ...

  7. ida 符号路径设置

    cfg/pdf.cfg 文件中主要有两个字段 PDBSYM_DOWNLOAD_PATH 这个字段可以注释掉 PDBSYM_SYMPATH 这个字段需要设置一个符号路径,具体设置方法和WinDBG的设置 ...

  8. JS中的垃圾回收(GC)

    垃圾回收(GC): 1. 就像人生活的时间长了会产生垃圾一样,程序运行过程中也会产生垃圾,这些垃圾积攒过多以后,会导致程序运行的速度过慢, 所以我们需要一个垃圾回收的机制,来处理程序运行中产生的垃圾. ...

  9. Java 整型数组只有一个整数是只出现一次的,其余都出现两次

    package writtenExamination; /** * @author lindaZ * @date 2015年10月22日 * @todo 找出数组中仅出现一次的数,其余数字出现两次 * ...

  10. Charles使用技巧

    过滤不必要请求 有些时候会抓取到很多自己不需要的请求 ,看起来不直观 只想抓包自己关心的地址 在外部设备抓包 比如你的手机设备 电脑模拟器等 本质就是你通过Charles开启一个代理端口,无论是外部设 ...