思路:

简单贪心,每次选择性价比最高的。

实现:

 #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; struct node
{
int t, d;
};
int n;
node a[];
int sum[]; bool cmp(const node & a, const node & b)
{
double x = a.d * 1.0 / a.t;
double y = b.d * 1.0 / b.t;
return x > y;
} int main()
{
cin >> n;
for (int i = ; i < n; i++)
{
scanf("%d %d", &a[i].t, &a[i].d);
}
sort(a, a + n, cmp);
sum[n - ] = a[n - ].d;
for (int i = n - ; i >= ; i--)
{
sum[i] = sum[i + ] + a[i].d;
}
long long total = ;
for (int i = ; i < n - ; i++)
{
total += sum[i + ] * * a[i].t;
}
cout << total << endl;
return ;
}

poj3262 Protecting the Flowers的更多相关文章

  1. POJ3262 Protecting the Flowers 【贪心】

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

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

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

  3. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  4. BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花

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

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

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

  6. 1634: [Usaco2007 Jan]Protecting the Flowers 护花

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

  7. bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...

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

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

  9. 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...

随机推荐

  1. mysql数据库隔离级别及其原理、Spring的7种事物传播行为

    一.事务的基本要素(ACID) 1.原子性(Atomicity):事务开始后所有操作,要么全部做完,要么全部不做,不可能停滞在中间环节.事务执行过程中出错,会回滚到事务开始前的状态,所有的操作就像没有 ...

  2. Vue.js新手入门指南

    最近在逛各大网站,论坛,以及像SegmentFault等编程问答社区,发现Vue.js异常火爆,重复性的提问和内容也很多,楼主自己也趁着这个大前端的热潮,着手学习了一段时间的Vue.js,目前用它正在 ...

  3. SDUT oj 选拔赛1 迷之好奇

    迷之好奇 Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 FF得到了一个有n个数字的集合.不要问我为什么,有钱,任性. FF很好奇 ...

  4. Elasticsearch分布式安装启动失败

    配置config目录下的 elasticsearch.yml  http.cors.enabled: true http.cors.allow-origin: "*" #分布安装. ...

  5. codeforces B. 4-point polyline 解题报告

    题目链接:http://codeforces.com/problemset/problem/452/B 题目意思:给出一个长为n,宽为 m 的矩形,要从这里面(包括边上)找出4个不同的点,使得以某一个 ...

  6. lucene 5的测试程序——API变动太大

    package hello; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import ...

  7. SPOJ:Stack Overflow(并查集)

    Stack is a basic data structure. Where 3 operation can be done- Push: You can push object to the sta ...

  8. Python mutilprocess模块之第二种创建进程方法--继承Process类

    '''创建新的进程的第二种方法: 使用类的方式,可以自己定义一个类,继承Process类,每次实例化这个类的时候, 就等于实例化一个进程对象 '''from multiprocessing impor ...

  9. wsdl 生成代码 WCF

    具体方法: 打开Microsoft Visual Studio 2008->Visual Studio Tools->Visual Studio 2008 命令提示窗口. 输入:wsdl ...

  10. bzoj4516

    后缀自动机 留个板子 upd:大概懂了 每次新加入的npRight集合肯定只有最后一个位置,那么求所有长得不一样的子串贡献就是Max-Min+1,因为Right集合只有这一个位置,所以这Max-Min ...