USACO 保护花朵 Protecting the Flowers, 2007 Jan
Description
约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的。他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草。可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园, 正在啃食他精心培育的花朵!约翰要立即采取行动,挨个把它们全部关回牛棚。 约翰牵走第 i 头奶牛需要 T i 分钟,因为要算来回时间,所以他实际需要 2 · T i 分钟。第 i 头奶牛 如果还在花园里逍遥,每分钟会啃食 Di 朵鲜花。但只要约翰抓住了它,开始牵走它的那刻开始,就 没法吃花了。请帮助约翰写一个程序来决定押送奶牛的顺序,使得花朵损失的数量最小。
Input Format
• 第一行:单个整数 N ,1 ≤ N ≤ 100000• 第二行到第 N + 1 行:第 i + 1 行有两个整数 T i 和 Di,2 ≤ T i ≤ 10 6 ; 1 ≤ Di ≤ 100
Output Format
• 单个整数:表示约翰损失的最小花朵数量
Sample Input
6 3 1 2 5 2 3 3 2 4 1 1 6
Sample Output
86
Hint
依次制服第六头,第二头,第三头,第四头, 第一头和第五头
Source
Protecting the Flowers, 2007 Jan由题目可知对于 Ta Da Tb Db 只对后状态影响 设影响为w;则后状态为∑Di(max(a,b)+1<=i<=n)若a排b前 w=Ta(∑Di+Db)+Tb*∑Di;若b排a前 w=Tb(∑Di+Da)+Ta*∑Di;消元后 发现 我们只要 对 Ta*Db<Tb*Da情况排序然后模拟即可
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int i,j,k,l,m,n;
long long ans,sum;
struct st{int w,t;}mu[100010];
bool cmp(const st x,const st y)
{if(x.t*y.w<y.t*x.w)return true;return false;
}
int main()
{
// freopen("xx.in","r",stdin);scanf("%d",&n);for(i=1;i<=n;sum+=mu[i].t*2,++i)scanf("%d%d",&mu[i].t,&mu[i].w);sort(mu+1,mu+n+1,cmp);long long num=sum;for(i=1;i<=n;++i){ans+=(sum-num)*mu[i].w;num-=mu[i].t*2;}printf("%lld",ans);
}
转载于:https://www.cnblogs.com/peter-le/p/6021175.html
USACO 保护花朵 Protecting the Flowers, 2007 Jan相关推荐
- [USACO 2007 Jan S]Protecting the Flowers
题目: [USACO 2007 Jan S]Protecting the Flowers ,哈哈,我们今天来看一道简单的贪心算法题嘛,这是选自USACO上的一道题,好了,我们一起来看看题意吧: 题目描 ...
- [BZOJ] 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 827 S ...
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 824 S ...
- POJ 3262 Protecting the Flowers 贪心(性价比)
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7812 Accepted: ...
- POJ3262 Protecting the Flowers【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8663 Accepted: ...
- [USACO07JAN]Protecting the Flowers S
题意:有n只奶牛正在吃花,农场主要把他们全都抓回去,给出每个奶牛得吃花速度和抓回去得时间(这里时间要乘2,来回),问约翰最少损失多少朵花. 题解:贪心 这题得贪心还是比较明显得,主要是通过分析前后两个 ...
- 牛客网 【每日一题】5月28日题目精讲 Protecting the Flowers
链接: 文章目录 题目描述 题意: 题解: 代码: 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目 ...
- Protecting the Flowers(POJ-3262)
Problem Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the g ...
- Protecting the flowers
时间限制:C / C ++ 1秒,其他语言2秒 空间限制:C / C ++ 32768K,其他语言65536K 64位IO格式:%lld 描述 农夫约翰去砍伐木头,照例让N(2≤N≤100,000)头 ...
最新文章
- 芯片如何储存信息_十四五规划之:芯片
- Ubuntu16.04 配置vnc4server
- Linux命令学习,学习这20条Linux命令,玩转你的树莓派!
- nginx 学习笔记(5) nginx调试日志
- mysql PREPARE用法_PHP5 mysqli的
- NTFS磁盘的安全与管理
- 单片机 PWM输出 c
- python列表片段_Python列表片段索引操作,python
- 02-对图像进行边界填充
- mysql安装pymyaql_python安装mysql的依赖包mysql-python操作
- 中国移民去哪儿 新京报
- 面试的那些事(收藏类)
- http://code.svnspot.com/ 免费代码托管
- 如何区分Babel中的stage-0,stage-1,stage-2以及stage-3(转)
- 微信小程序热潮或渐趋冷静
- 西蒙斯的赚钱秘籍:隐马尔科夫模型(HMM)的择时应用
- mac idea 快捷键
- RTE 2020 实时互联网大会参会指南——明天我们线上见!
- win2012 加入域
- Packet Tracer 和 Wirshark 抓取数据包
热门文章
- 兰州2021高考一诊成绩查询,2021兰州中考"一诊"成绩分析结果查询
- 开工啦,开工啦,2022开工了
- SDN第二章 Ubuntu开启/关闭防火墙
- SDN 作业提示器(持续更新)
- npm——安装教程、安装vue脚手架(ASP.NET Core微服务(五)——【vue脚手架解析接口】过度章节)
- ThinkPad紧凑型蓝牙键盘(0B47189)鼠标滚轮用法,F1到F12功能键的功能切换以及其他技巧
- MySQL 5.6版本GTID复制异常处理一例
- 《学习之道》第七章总结
- 三、Appium-python-UI自动化之元素定位uiautomatorviewer
- Swift5.1 语言指南(一) 关于Swift