POJ_3262 Protecting the Flowers 【贪心】
一、题面
二、分析
这题要往贪心上面想应该还是很容易的,但问题是要证明为什么比值关系就能满足。
可以选择几个去分析,入1-6 与 2-15 和 1-6 与2-5 和 1-6 与 2- 12。
三、AC代码
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- const int MAXN = 1e5+;
- struct Cow
- {
- int time, flower;
- }Data[MAXN];
- bool Cmp(const Cow a, const Cow b)
- {
- return (double)a.flower/a.time > (double)b.flower/b.time;
- }
- int main()
- {
- //freopen("input.txt", "r", stdin);
- int N;
- scanf("%d", &N);
- for(int i = ; i < N; i++)
- {
- scanf("%d %d", &Data[i].time, &Data[i].flower);
- }
- sort(Data, Data+N, Cmp);
- long long T = , Ans = ;
- for(int i = ; i < N; i++)
- {
- Ans += Data[i].flower*T;
- T += *Data[i].time;
- }
- printf("%I64d\n", Ans);
- return ;
- }
POJ_3262 Protecting the Flowers 【贪心】的更多相关文章
- POJ 3262 Protecting the Flowers 贪心(性价比)
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7812 Accepted: ...
- poj 3262 Protecting the Flowers 贪心 牛吃花
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11402 Accepted ...
- poj 3262 Protecting the Flowers 贪心
题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...
- poj -3262 Protecting the Flowers (贪心)
http://poj.org/problem?id=3262 开始一直是理解错题意了!!导致不停wa. 这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛 ...
- POJ3262 Protecting the Flowers 【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4418 Accepted: ...
- [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...
- 【POJ - 3262】Protecting the Flowers(贪心)
Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
- [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 885 So ...
随机推荐
- 一个小仓鼠的js动画
直接在网页打开就可以玩了: http://cdn.abowman.com/widgets/hamster/hamster.swf?up_bodyColor=f0e9cc&up_feetColo ...
- 在线创建MongoDB免费集群(MangoDB Atlas)
MongoDB Atlas是MongoDB的云服务,构建在亚马逊的AWS上,MongoDB允许用户在上面创建一个免费集群作为学习使用. 1. 注册MongoDB cloud账号: 访问www.mong ...
- Intent对象若干数据项的含义总结
Intent作为组件之间通信的手段和协议,包含了诸如Action.Data.Type.Category.Component.Extras和Flags等数据项,各自拥有各自的含义和作用.当调用组件发出一 ...
- Maven——依赖
一.依赖的范围 依赖的范围有几个可选值,我们用得到的是:compile.test.provided 三个. [1]从项目结构角度理解 compile 和 test 的区别 [2]从开发和运行这两个不同 ...
- hdu 4269 Defend Jian Ge
#include <cctype> #include <algorithm> #include <vector> #include <string> # ...
- IE浏览器和Firefox浏览器兼容性问题及解决办法
IE浏览器和Firefox浏览器兼容性问题及解决办法 为了方便大家阅读代码,以下以 IE 代替 Internet Explorer,以 MF/FF 代替 Mozzila Firefox : 1.//w ...
- Web API集成Azure AD认证
1.声明的介绍 基于角色的授权管理,适用于角色变化不大,并且用户权限不会频繁更改的场景. 在更复杂的环境下,仅仅通过给用户分配角色并不能有效地控制用户访问权限. 基于声明的授权有许多好处,它使认证和授 ...
- memcpy用法
函数原型 void *memcpy(void*dest, const void *src, size_t n); 功能 由src指向地址为起始地址的连续n个字节的数据复制到以destin指向地址为起始 ...
- 动态内存分配存在的问题(内存空洞)------c++程序设计原理与实践(进阶篇)
new的问题究竟在哪里呢?实际上问题出在new和delete的结合使用上.考察下面程序中内存分配和释放过程: while(1){ Big* p=new big; //...... Small* n1= ...
- mysql 字符串的截取与连接
mysql 字符串的截取 left() .right() . substring()[ mid() .substr() 等价于substring() ] .substring_index() l ...