一、题面

POJ3262

二、分析

这题要往贪心上面想应该还是很容易的,但问题是要证明为什么比值关系就能满足。

可以选择几个去分析,入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 【贪心】的更多相关文章

  1. POJ 3262 Protecting the Flowers 贪心(性价比)

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7812   Accepted: ...

  2. poj 3262 Protecting the Flowers 贪心 牛吃花

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11402   Accepted ...

  3. poj 3262 Protecting the Flowers 贪心

    题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...

  4. poj -3262 Protecting the Flowers (贪心)

    http://poj.org/problem?id=3262 开始一直是理解错题意了!!导致不停wa. 这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛 ...

  5. POJ3262 Protecting the Flowers 【贪心】

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4418   Accepted: ...

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

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

  7. 【POJ - 3262】Protecting the Flowers(贪心)

    Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...

  8. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

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

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

随机推荐

  1. fastcgi_finish_request

    本问原地址 http://www.phpddt.com/php/fastcgi_finish_request.html 某些操作,如用户注册后邮件发送,记录日志等一些耗时操作可以转化为异步操作!当PH ...

  2. SaeMail使用示例

    SAE的官方文档:http://apidoc.sinaapp.com/sae/SaeMail.html SaeMail类的具体实现:http://apidoc.sinaapp.com/__fileso ...

  3. 22-Two(公共子序列的个数)

    http://acm.hdu.edu.cn/showproblem.php?pid=5791 Two Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. C语言代码里不能用goto?

    当我学C语言时,老师整天告诉我:"不要使用goto, 这是一个坏习惯, 这种写法很烂,而且很危险!"等等. 但是为什么那么多内核程序员那么喜欢用goto呢? 在这段linux内核  ...

  5. tensor 维度 问题。

    tf.argmax takes two arguments: input and dimension. example: tf.argmx(arr, dimension = 1). or tf.arg ...

  6. ubuntu安装软件包apt-get和dpkg方法

    1apt方法 安装软件 apt-get install softname1 softname2 softname3…… 卸载软件 apt-get remove softname1 softname2 ...

  7. 内存中DataTable去除重复行

    删除内存中DataTable表的重复行 假设在内存中(不是数据库中)有两个表: 表一:TableA Name Phone 张三 123456 李四 123457 王五 1234568 表二:Table ...

  8. AutoLayout自动布局之VFL语言代码实现(一个神奇的语言)

    一.什么是VFL语言?为什么要VFL语言? VFL全称是Visual Format Language,翻译过来是“可视化格式语言” VFL是苹果公司为了简化Autolayout的编码而推出的抽象语言 ...

  9. 献上一款漂亮的手写PHP验证码

    献上一款漂亮的PHP验证码,可以根据个人需求作调整,代码如下(审美观不同,欢迎吐槽): <?php /** * Author: xiongwei * Email: 695704253@qq.co ...

  10. C#中ref和out的作用和区别

    相同点:方法的定义和调用都必须显示使用ref.out关键字.都会导致参数按引用传递. 不同点:传递给ref关键字的参数必须赋初始值,而out不用.out关键字会清空变量,即使变量已经赋值也不行,退出函 ...