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. FastJson 对enum的 序列化(ordinal)和反序列化

    目前版本的fastjon默认对enum对象使用WriteEnumUsingName属性,因此会将enum值序列化为其Name. 使用WriteEnumUsingToString方法可以序列化时将Enu ...

  2. JavaScript中的对象描述符(属性特性)

    我们先创建一个对象: var person = { name: "Nicholas", _job: "Software Engineer", sayName: ...

  3. EControl平台测试向生产版本工程切换说明

    第一步,备份生产环境版本,假设生产环境版本工程名为SEHEControl,记录版本说明第二部,拷贝测试版本到新文件夹,假设测试版本工程名为SEHEControlTest第三步,进入工程文件夹,修改SL ...

  4. mysql 数据备份与恢复

    1.mysql的备份 命令:"mysqldump -u root -p 数据库名 [表名] > 备份文件名" 不写表名默认备份所有整个数据库. 注意:备份的文件中没有创建数据 ...

  5. ubuntu,windows 卸载安装mysql

    首先删除mysql: sudo apt-get remove mysql-* 1 然后清理残留的数据 dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dp ...

  6. [dt]世纪历史长河年代表

    年代口诀 夏商与西周, 东周分两段, 春秋和战国, 一统秦两汉, 三分魏蜀吴, 二晋前后延, 南北朝并列, 隋唐五代传, 宋元明清后, 皇朝至此完. 中国历史长河年代表 参考: 中国历史朝代顺序表.年 ...

  7. 测试人员需要了解的sql知识(提高篇)

    上一篇写了一些基础的sql知识,这里再深挖一些常用的 ------------------------------------------------------------------骄傲的分割线- ...

  8. HDU5012:Dice(bfs模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 Problem Description There are 2 special dices on the ...

  9. Variational Approximate Inference

    图模型(Graphical Models)是一个用来表示概率模型的工具.所谓概率模型,也就是在刻画一组随机变量之间的相互关系.图模型就是用来显式地刻画这些变量之间关系的.在 图模型中,每个变量由图中的 ...

  10. 机器学习理论基础学习1——频率派 VS 贝叶斯派

    频率派 贝叶斯派 theta是个未知的常量,X是随机变量, theta是个随机变量,X是随机变量 MLE最大似然估计 MAE最大后验概率 统计机器学习,优化问题 1)建立模型.概率 2)定义损失函数 ...