题意:
有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 【贪心】的更多相关文章

  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 (贪心)

    http://poj.org/problem?id=3262 开始一直是理解错题意了!!导致不停wa. 这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛 ...

  4. poj 3262 Protecting the Flowers 贪心

    题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...

  5. poj 3262 Protecting the Flowers

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

  6. POJ 3362 Protecting the Flowers

    这题和金华区域赛A题(HDU 4442)是一样的做法. 对两个奶牛进行分析,选择两个奶牛总花费少的方式排序. bool cmp(const X&a,const X&b){ return ...

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

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

  8. POJ3262 Protecting the Flowers 【贪心】

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

  9. [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心

    Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...

随机推荐

  1. pycharm sql语句警告

    产生原因为没有配置数据库,配置数据库,似乎没什么作用 那么,直接去掉他的警告提示 找到setting->editor->inspections,然后找到右边sql下的 No data so ...

  2. 【转】LR分析法

    转自:http://guanjy0129.blog.163.com/blog/static/1115494452010614113333509/ LR分析法的归约过程是规范推导的逆过程,所以LR分析过 ...

  3. 夏令时(DST)测试

    夏令时测试是比较小众的测试,主要针对在有夏令时的国家使用的软件,如果你接触到了这方面的测试,说明你在挣国外的钱:).   话不多说,先来介绍下什么是夏令时:   夏时制,夏时令(Daylight Sa ...

  4. bzoj 1724 优先队列 切割木板

    倒着的石子合并,注意不是取当前最长木板贪心做,而是取当前最小累加答案: 例如 4 5 6 7 若按第一种思路:ans=22+15+9 第二种:ans=22+13+9,可以先从中间某一块分开,这样答案更 ...

  5. C - Portals Gym - 102006C (网络流最小割)

    题目链接:https://cn.vjudge.net/contest/283918#problem/C 题目大意:T个测试数据,然后给你一个字符串,每一个字符串包括‘s’,‘t’,‘o’,‘#’,‘. ...

  6. sqlplus连接远程数据库

    方式一:简易连接,不用进行网络配置,其实就是tnsname.ora文件 命令:sqlplus 用户名/密码@ip地址[:端口]/service_name [as sysdba] 示例:sqlplus ...

  7. 【Python】批量爬取网站URL测试Struts2-045漏洞

    1.概述都懒得写了.... 就是批量测试用的,什么工具里扣出来的POC,然后根据自己的理解写了个爬网站首页URL的代码... #!/usr/bin/env python # -*- coding: u ...

  8. GCC的符号可见性——解决多个库同名符号冲突问题

    引用自:https://github.com/wwbmmm/blog/wiki/gcc_visibility 问题 最近项目遇到一些问题,场景如下 主程序依赖了两个库libA的funcA函数和libB ...

  9. High level GPU programming in C++

    https://github.com/prem30488/C2CUDATranslator http://www.training.prace-ri.eu/uploads/tx_pracetmo/GP ...

  10. ActiveMQ 入门Nodejs版

    ActiveMQ 入门下载与安装 官方下载地址 解压,运行bin/win[32|64]/activemq[.bat] 启动服务 环境信息 控制台: http://localhost:8161 默认端口 ...