POJ_3262 Protecting the Flowers 【贪心】
一、题面
POJ3262
二、分析
这题要往贪心上面想应该还是很容易的,但问题是要证明为什么比值关系就能满足。
可以选择几个去分析,入1-6 与 2-15 和 1-6 与2-5 和 1-6 与 2- 12。
三、AC代码
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #include <fstream> 5 using namespace std; 6 7 const int MAXN = 1e5+6; 8 9 struct Cow 10 { 11 int time, flower; 12 }Data[MAXN]; 13 14 bool Cmp(const Cow a, const Cow b) 15 { 16 return (double)a.flower/a.time > (double)b.flower/b.time; 17 } 18 19 int main() 20 { 21 //freopen("input.txt", "r", stdin); 22 int N; 23 scanf("%d", &N); 24 for(int i = 0; i < N; i++) 25 { 26 scanf("%d %d", &Data[i].time, &Data[i].flower); 27 } 28 sort(Data, Data+N, Cmp); 29 long long T = 0, Ans = 0; 30 for(int i = 0; i < N; i++) 31 { 32 Ans += Data[i].flower*T; 33 T += 2*Data[i].time; 34 } 35 printf("%I64d\n", Ans); 36 return 0; 37 }
View Code
转载于:https://www.cnblogs.com/dybala21/p/10150761.html
POJ_3262 Protecting the Flowers 【贪心】相关推荐
- 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: ...
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 824 S ...
- [BZOJ] 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 827 S ...
- [USACO 2007 Jan S]Protecting the Flowers
题目: [USACO 2007 Jan S]Protecting the Flowers ,哈哈,我们今天来看一道简单的贪心算法题嘛,这是选自USACO上的一道题,好了,我们一起来看看题意吧: 题目描 ...
- USACO 保护花朵 Protecting the Flowers, 2007 Jan
Description 约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的.他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草.可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园 ...
- 牛客网 【每日一题】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 ...
- [USACO07JAN]Protecting the Flowers S
题意:有n只奶牛正在吃花,农场主要把他们全都抓回去,给出每个奶牛得吃花速度和抓回去得时间(这里时间要乘2,来回),问约翰最少损失多少朵花. 题解:贪心 这题得贪心还是比较明显得,主要是通过分析前后两个 ...
最新文章
- ubuntu 16.04 python3 使用ryu
- Erlang模块gen_tcp翻译
- 2410 中断过程处理分析
- Matlab | Matlab从入门到放弃(5)——矩阵与format
- [原]Java程序员的JavaScript学习笔记(12——jQuery-扩展选择器)
- 一个含n个顶点和e条弧的有向图以邻接矩阵表示法为存储结构,则计算该有向图中某个顶点出度的时间复杂度为
- 增加VirtualBox虚拟机的磁盘空间大小(Host:Win7 VirtualBox5.0.16 VM:Win10)
- 想尝试搭建图像识别系统?这里有一份TensorFlow速成教程
- Linux下MySQL表名区分大小写
- 安卓java摄像机的_在Android系统中调用系统前置摄像头
- Picasso,Glide,Fresco对比分析
- Mysql 省市县乡 地址分割
- java实现PDF转tif格式并且设置颜色和dpi
- 阿里西西网页特效代码演示中心-QQ在线客服代码演示
- POI解析docx与doc文档中的难点归纳
- 自定义微博小尾巴 源码+解析
- 要么出众,要么出局 定制化让企业更出众
- VPN入门教程:基本概念、使用方法及思科模拟器实践
- 软文写作技巧:文字表达能力是关键
- 进入bios或者安全模式
热门文章
- pytorch如何定义损失函数_对比PyTorch和TensorFlow的自动差异和动态模型
- html 消息通知声音,ajax实现web页面的消息实时提醒时播放提示音
- php url传递变量,php – 在laravel中通过url传递变量
- 对口升学计算机组装与维护,对口升学信息技术(计算机)类2017年专业课考试大纲...
- php 新浪url,PHP URL函数详解
- AAS的完整形式是什么?
- Java PriorityQueue clear()方法与示例
- 对视频中的特征颜色物体(青色水杯)进行跟踪
- Java——IO流(序列流)
- win7 php 上传文件,在LNMP原来的基础上,win7环境下如何上传PHP文件到Linux环境下...