poj -3262 Protecting the Flowers (贪心)
http://poj.org/problem?id=3262
开始一直是理解错题意了!!导致不停wa。
这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛需要的时间和牛在花园每分钟吃多少花朵,问你怎么安排让损失最小。
这题单独按time和eat排序都不行,得按它们的比率来排,如果是选择eat/time 则从大到小排,time/eat则从小到大排,但是不会严格证明。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define N 100005
using namespace std; struct point
{
int x,y;
double d;
bool operator <(const point &a) const
{
return d>a.d;
}
}p[];
int main()
{
//Read();
int n;
ll sum,t;
while(~scanf("%d",&n))
{
sum=t=;
for(int i=;i<n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].d=p[i].y*1.0/p[i].x;
t+=p[i].y; //这样处理 方便计算
}
sort(p,p+n);
//for(int i=0;i<n;i++) printf("%d %d\n",p[i].x,p[i].y);
for(int i=;i<n;i++)
{
t-=p[i].y;
sum+=p[i].x*t*;
}
printf("%lld\n",sum);
}
return ;
}
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 贪心
题意:给定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 3262 Protecting the Flowers 【贪心】
题意:有n个牛在FJ的花园乱吃.所以FJ要赶他们回牛棚.每个牛在被赶走之前每秒吃Di个花朵.赶它回去FJ来回要花的总时间是Ti×2.在被赶走的过程中,被赶走的牛就不能乱吃 思路: 先赶走破坏力大的牛假 ...
- 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朵 ...
随机推荐
- redis提示Could not get a resource from the pool(jedis连接池配置)
起初在JedisPool中配置了50个活动连接,但是程序还是经常报错:Could not get a resource from the pool 连接池刚开始是这样配置的: JedisPoolCon ...
- <context:annotation-config> 跟 <context:component-scan>诠释及区别
<context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注 ...
- [Bug]没有对“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files”的写访问权限
问题 环境WIN8.1 x64,新安装的vs与iis,在部署网站时,出现该异常信息.本地机作为测试机,就部署一个站点进行测试,没想到出现这个错误. 解决方案 如果你访问上面的那个路径,你会发现并没有那 ...
- YARN应用程序的开发步骤
开发基于YARN的应用程序需要开发客户端程序和AppMaster程序: 我们基于程序自带的例子来实现提交application 到YARN的ResourceManger. Distributed Sh ...
- 理解Session的几种模式
一.写在前面 我们在使用ASP.NET开发的过程中,有时会进行数据存储以实现请求前后的状态保持(HTTP是无状态保持的协议),而Session作为一种快速简单易于实现的方式被我们经常使用,当然如果出于 ...
- Java异常类和自定义异常类
自定义异常类: public class ExtendsException extends Exception { private static final long serialVersionUID ...
- Codeigniter整合Tank Auth权限类库的教程
Codeigniter整合Tank Auth权限类库的教程一开始找了很多CodeIgniter的类库,觉得都不怎么样,后来干脆自己通过CI的钩子系统写了权限管理.但是还是不怎么满意,后来有人推荐tan ...
- ExtJs之Ext.getCmp
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- poj 1797(最短路变形)
题目链接:http://poj.org/problem?id=1797 思路:题目意思很简单,n个顶点,m条路,每条路上都有最大载重限制,问1->n最大载重量.其实就是一最短路的变形,定义wei ...
- 更改cmd代码页,修正语言显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 rem 英文 chcp 437 rem 日文 chcp 932 rem 简体中文 chcp 936 re ...