一、题面

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. 788. Rotated Digits 旋转数字

    [抄题]: X is a good number if after rotating each digit individually by 180 degrees, we get a valid nu ...

  2. Hadoop完全分布式环境搭建(三)——基于Ubuntu16.04安装和配置Java环境

    [系统环境] 1.宿主机OS:Win10 64位 2.虚拟机软件:VMware WorkStation 12 3.虚拟机OS:Ubuntu16.04 4.三台虚拟机 5.JDK文件:jdk-8u201 ...

  3. 更改windows服务的配置文件(app.config)必须重启服务才能生效吗?

    这个问题是前一阶段写windows服务碰到的.本来在写获取配置文件的某个配置的值的时候,通常我都是写类似下面的这么一个静态方法来获取: 1: /// <summary> 2: /// 获取 ...

  4. tensorflow 中 feed的用法

    Feed 上述示例在计算图中引入了 tensor, 以常量或变量的形式存储. TensorFlow 还提供了 feed 机制, 该机制 可以临时替代图中的任意操作中的 tensor 可以对图中任何操作 ...

  5. 932F Escape Through Leaf

    传送门 题目大意 https://www.luogu.org/problemnew/show/CF932F 分析 我们可以从叶子向根每次插入b和ans 所以我们不难发现就是相当于插入线段 于是李超树+ ...

  6. ESP8266-iot-3

    ESP8266 WIFI操作 参考资料 模式选择 程序: 把之前的Helloworld程序复制过来改成wifi工程 先输出获取的当前模式 编译后会出错,因为os_printf的头文件没有被包含进来 结 ...

  7. SQL Server 时间类型转换函数

    cast ( expression as data_type(length))convert ( data_type (length), expression, style) //如果未指定 leng ...

  8. 最近做手机端,GPS,微信QQ分享总结的问题

    Android端 百度地图: 1.libs包中armeabi下liblocSDK4d.so文件丢失,导致百度定位失效. 微信分享: 1.分享App,app的内容(图片加描述)不能超过32kb ,不然无 ...

  9. 如何让win32对话框居中显示

    在编写win32对话框程序,如果是用visual studio建的win32对话框程序,默认是不居中显示的,about 对话框也是这样的,用资源编辑器打开,可以在属性里面设置居中center 为tur ...

  10. web3部署智能合约碰到的一个奇怪问题

    都是gasLimit惹的祸 解决一个奇怪问题Error: Number can only safely store up to 53 bits 原来好好的node endpointtest.js ,结 ...