一、题面

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. centos 搭建docker环境

    我有一台便宜的腾讯云服务器,当然配置自然也是最低的,只是用来平常玩一玩,学习的用处,下面介绍一下我在上面搭建docker的心得,共勉一下. 安装与配置 Docker 安装 Docker Docker ...

  2. php const static define 基本用法和区别

    const  定义一些在运行时不能被改变的数值.一旦值被改变,则会发生错误. 特性 只能用类名访问.不需要用 $  符号 <?php class test{ const pi=123.12321 ...

  3. 在Windows里定时执行一个Python文件

    一.系统环境 操作系统:Win7 64位 二.说明 1.建立一个dos批处理文件 例: @echo off C: cd C:\work\python python aaa.py exit 2.利用Wi ...

  4. 数字图像处理实验(13):PROJECT 05-04,Parametric Wiener Filter 标签: 图像处理MATLAB 2017-05-27 10:59

    实验要求: Objective: To understand the high performance of the parametric Wiener Filter in image restora ...

  5. Java虚拟机学习总结之OutOfMemoryError异常

    参考:深入理解java虚拟机一书 开始之前,我们也应当搞清楚连个概念,内存泄漏Memory Leak 内存溢出: 内存泄漏:程序中间动态分配了内存,但是在程序结束时没有释放内存,造成这部分内存不可用. ...

  6. numpy.loadtxt() 出现codecError_____ Excel 做矩阵乘法

    1) 用 numpy读入csv文件是报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal m ...

  7. Recurrent Neural Network(递归神经网络)

    递归神经网络(RNN),是两种人工神经网络的总称,一种是时间递归神经网络(recurrent neural network),另一种是结构递归神经网络(recursive neural network ...

  8. 编写高质量代码改善C#程序的157个建议——建议5: 使用int?来确保值类型也可以为null

    建议5: 使用int?来确保值类型也可以为null 基元类型为什么需要为null?考虑两个场景: 1)数据库中一个int字段可以被设置为null.在C#中,值被取出来后,为了将它赋值给int类型,不得 ...

  9. 测试中常用到的linux命令

    1. man         格式化以及列出命令的(在线)操作手册.         使用方法                 man [ -options ] name       man man ...

  10. 团队项目第六周-Alpha阶段项目复审(深海划水队)

    经小组讨论后得出以下排名: 队名 优点 缺点 排名 大猪蹄子队 界面优美,功能简洁易懂,单词解释较为完善 互动方式.操作简易性有待优化,有部分功能尚未完成 1 Running Duck队 基本功能已经 ...