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

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

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

  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. ...

  3. P2878 [USACO07JAN]保护花朵Protecting the Flowers

    一个类似国王游戏的贪心 话说要是先做了这个题,国王游戏之余懵逼这么久吗? #include<iostream> #include<cstdio> #include<alg ...

  4. 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. ...

  5. USACO 保护花朵 Protecting the Flowers, 2007 Jan

    Description 约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的.他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草.可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园 ...

  6. USACO Protecting the Flowers

    洛谷 P2878 [USACO07JAN]保护花朵Protecting the Flowers 洛谷传送门 JDOJ 1009: 护花 JDOJ传送门 Description FJ出去砍木材去了,把N ...

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

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

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

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

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

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

随机推荐

  1. Yii2 使用json 和设置component 中'format' => yii\web\Response::FORMAT_JSON 的区别

    在Yii2中如果设置了 'response' => [  'format' => yii\web\Response::FORMAT_JSON,  'charset' => 'UTF- ...

  2. TFS二次开发07——锁定(Lock)和解锁(UnLock)

    一:锁定(Lock) string tpcURL = "http://192.168.83.62:8080/"; TfsTeamProjectCollection tpc = ne ...

  3. HUST 1605 Gene recombination(广搜,位运算)

    题目描述 As a gene engineer of a gene engineering project, Enigma encountered a puzzle about gene recomb ...

  4. 肖俊:HPE IT 的DevOps 实践分享

    本篇文章来自于HPE和msup共同举办的技术开放日HPE测试技术总监肖俊的分享,由壹佰案例整理编辑. 一.DevOps含义解析 这是DevOps的趋势图.DevOps这个概念大概是在2009年被提出来 ...

  5. 从经典面试题看java中类的加载机制

    1.概述 类加载是Java程序运行的第一步,研究类的加载有助于了解JVM执行过程,并指导开发者采取更有效的措施配合程序执行,对理解java虚拟机的连接模型和java语言的动态性都有很大帮助. 由于Ja ...

  6. 东哥讲义2 - 基于TCP,UDP协议的攻击,分析与防护

    TCP SYN FLOOD 攻击 正常的TCP三次握手过程: 处于SYN FLOOD攻击状态时的三次握手过程: 查看示例:x_syn.c文件,一个实现了自定义mac,ip,tcp头部的syn floo ...

  7. centos source install

    CentOS Kernel Source Install Mar 12th, 2012 | Comments CentOS kernel source install, first off if yo ...

  8. Arrow-一个最好用的日期时间Python处理库

    https://www.jianshu.com/p/c878bb1c48c1 写过Python程序的人大都知道,Python日期和时间的处理非常繁琐和麻烦,主要有以下几个问题: 有众多的package ...

  9. 解决下载的CHM文件无法显示网页问题

    问题症状:打开CHM文件,左边目录齐全,可右边边框里却是无法显示网页. 解决方法:方法一:修改注册表1)新建一个文本文件2)添加如下内容:REGEDIT4[HKEY_LOCAL_MACHINE\SOF ...

  10. Python开发【笔记】:关闭线程的方法

    1.通过API进行线程关闭 import threading import time import inspect import ctypes def _async_raise(tid, exctyp ...