POJ 3262 Protecting the Flowers 【贪心】
题意:
有n个牛在FJ的花园乱吃。
所以FJ要赶他们回牛棚。
每个牛在被赶走之前每秒吃Di个花朵。赶它回去FJ来回要花的总时间是Ti×2。在被赶走的过程中,被赶走的牛就不能乱吃
思路:
先赶走破坏力大的牛
假设序列都由二元组组成,二元组是由T和D组成,那么对一个序列有相邻的两头牛是这样的
..........(a, b) ,(c, d)....................
如果(a,b)和(c,d)交换位置了
变成新序列
..........(c,d),(a,b).......................
假设在这之前FJ已经花了x时间了。
那么赶完这两头牛的损失的量就分别为
x*b + (x + a ) * d
x*d +(x + c) * b
二者做差
得到ad - bc
若ad < bc 则有第一个序列优于第二个。
//bool cmp(cow x, cow y)
//{
// return x.t * y.d < x.d * y.t;
//}
#include <iostream>
#include <cstdio>
#include <queue>
#include <math.h>
#include <cstring>
#include <algorithm>
using namespace std; struct cow
{
double t,d;
}a[2000001];
bool cmp(cow x,cow y)
{
return x.d/x.t > y.d/y.t;
}
int main()
{
int n;
scanf("%d", &n);
for(int i=0;i<n;i++)
scanf("%lf%lf",&a[i].t,&a[i].d);
sort(a,a+n,cmp);
long long sum=0,s=0;
for(int i=0;i<n;i++)
{
sum+=2*s*a[i].d;
s+=a[i].t;
}
cout<<sum<<endl;
return 0;
}
POJ 3262 Protecting the Flowers 【贪心】的更多相关文章
- POJ 3262 Protecting the Flowers 贪心(性价比)
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7812 Accepted: ...
- poj 3262 Protecting the Flowers 贪心 牛吃花
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11402 Accepted ...
- poj -3262 Protecting the Flowers (贪心)
http://poj.org/problem?id=3262 开始一直是理解错题意了!!导致不停wa. 这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛 ...
- poj 3262 Protecting the Flowers 贪心
题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- POJ 3362 Protecting the Flowers
这题和金华区域赛A题(HDU 4442)是一样的做法. 对两个奶牛进行分析,选择两个奶牛总花费少的方式排序. bool cmp(const X&a,const X&b){ return ...
- 【POJ - 3262】Protecting the Flowers(贪心)
Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...
- POJ3262 Protecting the Flowers 【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4418 Accepted: ...
- [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...
随机推荐
- Java Calendar详解
网上看到的一篇,码一下.侵删 一:字段和方法的信息 YEAR 字段: public static final int YEAR ; 指示年的 get 和 set 的字段数字.这是一个特定于日历的值: ...
- 微信接口开发之高级篇系列【微信JS-SDK】
PHP微信公众平台开发高级篇—微信JS-SDK 第一步.绑定域名: 第二步.引入JS文件: 第三部.通过Config接口注入权限验证配置 第四部.通过Read接口处理成功验证 第五部.通过Error接 ...
- Nginx管理脚本
#!/bin/bash # chkconfig: # description: Start/Stop Nginx server path=/application/nginx/sbin pid=/ap ...
- 用ajax传递json,返回前台的中文乱码问题
java项目中用ajax传递json,返回前台时中文出现问号(乱码问题)的解决办法 首先看一下没有解决前的状态: 我用的框架是ssm,在springMVC中我配置了编码格式为utf-8,每个jsp页面 ...
- 一、GPIO操作
1.1 硬件原理图 四个引脚接到LED上,跟别是GPF4,GPF5,GPF6和GPF7,前三个引脚分别控制三个LED,GPF7此引脚作为DM9000网卡的中断. 发光二极管的正极接3.3V电源,负极接 ...
- MySQL5.7主从复制配置
1 my.cnf文件 配置 binlog_format = ROW log_bin_trust_function_creators=1 log-error = /usr/local/mysql/dat ...
- getattr getattribute setattr hasattr delattr
getattr是返回对象属性value的函数,用法:getattr(object,attribute_name[,default]) 如果对象拥有属性,则返回属性value,如果对象没有该属性并且也没 ...
- PHP - CentOS下开发运行环境搭建(Apache+PHP+MySQL+FTP)
本文介绍如何在 Linux下搭建一个 PHP 环境.其中 Linux 系统使用是 CentOS 7.3,部署在阿里云服务器上. 1,连接登录服务器 拿到服务器的 ip.初始密码以后.我们先通过远程 ...
- oracle怎么给表和列加注释
oracle添加注释的语法为: comment on column 字段名 is '注释名' 举例: 创建表: CREATE TABLE t1{ id varchar2(32) primary ke ...
- AWTK(Toolkit AnyWhere): 为嵌入式、手机和桌面开发的通用GUI【转】
转自:https://blog.csdn.net/absurd/article/details/80958279 AWTK = Toolkit AnyWhere AWTK是吸取了FTK和CanTK的精 ...