poj3262 Protecting the Flowers
思路:
简单贪心,每次选择性价比最高的。
实现:
#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的更多相关文章
- POJ3262 Protecting the Flowers 【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4418 Accepted: ...
- 【POJ - 3262】Protecting the Flowers(贪心)
Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 448 So ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 493 So ...
- bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...
- [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 885 So ...
- 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...
随机推荐
- SQL Server 2012 安装图解教程(附sql2012下载地址)
在安装微软最新数据库SQL Server 2012之前,编者先确定一下安装环境:Windonws 7 SP1,32位操作系统.CPU是2.1GHz赛扬双核T3500,内存2.93GB. sql2012 ...
- POJ3273 Monthly Expense —— 二分
题目链接:http://poj.org/problem?id=3273 Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Tota ...
- apt-get update 问题 及gcc高亮
一 gcc高亮 gcc 高亮有好几种方法. 参考 http://www.cokco.cn/thread-39909-1-1.html 这个教程: (1) git clone https://githu ...
- NSError分析
在iOS开发中,NSError的使用非常常见,使用也比较简单,也正因为简单,所以对这一部分知识不甚注重.但是近期在做app底层网络封装时发现了一些问题.我使用的网络框架是AFNetworking,AF ...
- Video.js事件
Home 膘叔 » Archives 文章: 备份一个video的JS [打印] 分类: Javascript 作者: gouki 2012-02-16 17:58 备份一个JS,不是为了代码很优秀, ...
- Centos6.5 6.6 (均可) 重置密码或强行破解root密码 简单操作
centos忘记root密码怎么重置root密码? 使用Linux系统的时候root密码是十分关键的安全机制. 但是假设那天丢失了root密码的话问题就严重了. 百牛信息技术bainiu.ltd整理发 ...
- Java多线程:线程状态以及wait(), notify(), notifyAll()
一. 线程状态类型1. 新建状态(New):新创建了一个线程对象.2. 就绪状态(Runnable):线程对象创建后,其他线程调用了该对象的start()方法.该状态的线程位于可运行线程池中,变得可运 ...
- UI:动画
参考 UIView 层级管理.触摸.检测手机是否横屏.调整设备的方向 动画:为了提高用户的体验 View层的动画.UIlayer层的动画.UIView改变视图效果.UIlayer的绘图框架 #prag ...
- linux中vfork对打开文件的处理
vfork和fork fork()函数是拷贝一个父进程的副本,拥有独立的代码段 数据段 堆栈空间 然而vfork是共享父亲进程的代码以及代码段 vfork是可以根据需要复制父进程空间,这样很大程度的提 ...
- (水题)Codeforces - 327C - Magic Five
https://codeforces.com/problemset/problem/327/C 因为答案可以有前导零,所以0和5一视同仁.每个小节内,以排在第 $i$ 个的5为结尾的序列即为在前面 $ ...