BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 448 Solved: 276
[Submit][Status]
Description
Farmer John went to cut some wood and left N
(2 <= N <= 100,000) cows eating the grass, as usual. When he returned, he
found to his horror that the cows were in his garden eating his beautiful
flowers. Wanting to minimize the subsequent damage, FJ decided to take immediate
action and transport the cows back to their barn. Each cow i is at a location
that is Ti minutes (1 <= Ti <= 2,000,000) away from the barn. Furthermore,
while waiting for transport, she destroys Di (1 <= Di <= 100) flowers per
minute. No matter how hard he tries,FJ can only transport one cow at a time back
to the barn. Moving cow i to the barn requires 2*Ti minutes (Ti to get there and
Ti to return). Write a program to determine the order in which FJ should pick up
the cows so that the total number of flowers destroyed is minimized.
Input
* Line 1: A single integer
N * Lines 2..N+1: Each line contains two
space-separated integers, Ti and Di, that describe a single cow's
characteristics
第1行输入N,之后N行每行输入两个整数Ti和Di.
Output
* Line 1: A single integer that is the
minimum number of destroyed flowers
一个整数,表示最小数量的花朵被吞食.
Sample Input
3 1
2 5
2 3
3 2
4
1
1 6
Sample Output
HINT
约翰用6,2,3,4,1,5的顺序来运送他的奶牛.
Source
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000+100
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
struct rec{int x,y;}a[maxn];
int n;
inline bool cmp(rec a,rec b)
{
return a.x*b.y<a.y*b.x;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
ll sum=;
for(int i=;i<=n;i++)a[i].x=read(),a[i].y=read(),sum+=a[i].y;
sort(a+,a+n+,cmp);
ll ans=;
for(int i=;i<=n;i++)
{
sum-=a[i].y;
ans+=sum**a[i].x;
}
printf("%lld\n",ans);
return ;
}
BZOJ1634: [Usaco2007 Jan]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 ...
- [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...
- 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】[Usaco2007 Jan]Protecting the Flowers 护花 贪心
题目描述 Farmer John went to cut some wood and left N (2 <= N <= 100,000) cows eating the grass, a ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花
Description Farmer John went to cut some wood and left N (2 <= N <= 100,000) cows eating the g ...
- 【BZOJ】1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1634 贪心.. 我们发现,两个相邻的牛(a和b)哪个先走对其它的牛无影响,但是可以通过 a的破坏花× ...
- BZOJ 1634 [Usaco2007 Jan]Protecting the Flowers 护花:贪心【局部分析法】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1634 题意: 约翰留下他的N只奶牛上山采木.可是,当他回来的时候,他看到了一幕惨剧:牛们正 ...
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花【贪心】
因为交换相邻两头牛对其他牛没有影响,所以可以通过交换相邻两头来使答案变小.按照a.t*b.f排降序,模拟着计算答案 #include<iostream> #include<cstdi ...
随机推荐
- Object -C NSSet -- 笔记
// // main.m // NSSET // // Created by facial on 25/8/15. // Copyright (c) 2015 facial_huo. All ...
- 浅谈Manacher算法与扩展KMP之间的联系
首先,在谈到Manacher算法之前,我们先来看一个小问题:给定一个字符串S,求该字符串的最长回文子串的长度.对于该问题的求解.网上解法颇多.时间复杂度也不尽同样,这里列述几种常见的解法. 解法一 ...
- 数字信号处理Day2-小波基与规范正交化
我们有这么一张灰度图64*64 我们能够定义出4096个基,各自是某一位是0其它是1,在这样的情况下,假设我们传输图片,那么就相当于传输原始数据 如果传到一半,网络坏了. 于是,我们得到 我们能够计算 ...
- [Redux] Writing a Todo List Reducer (Adding a Todo)
Learn how to implement adding a todo in a todo list application reducer. let todo = (state = [], act ...
- 二叉排序树BST代码(JAVA)
publicclassTest{ publicstaticvoid main(String[] args){ int[] r =newint[]{5,1,3,4,6,7 ...
- hdu_1875_畅通工程再续 prim和kruskal
这个题是个典型的最小生成树的题目,但是刚开始怎么都过不了,后来发现两种写法都有疏忽,但是prim的到目前为止不懂为什么刚开始的不对,kruskal算法,并查集的初始条件从0开始写成从1开始了,所以已知 ...
- mongodb入门教程二
title: mongodb入门教程二 date: 2016-04-07 10:33:02 tags: --- 上一篇文章说了mongodb最基本的东西,这边博文就在深入一点,说一下mongo的一些高 ...
- C# 面向对象 , 类与对象
一,类的字段 类的字段, 就是类里面的 数据. 二,类的方法 1 , 函数的重载 , 如何判断: 是由两个或多个同名函数组成的,但是函数要有不同的参数.或个数.(参数 是函数的输入的东西) shu ...
- HTML学习(1)
1.缩写和首字母缩写<abbr><acronym> <abbr title="etcetera">etc.</abbr> <a ...
- JAVA泛型那些事儿
本篇内容源于本人一个好友sgpro提供的java学习例子,现拿出来给大家分享. 此例子非常直观的通过代码讲解了java泛型的用法和好处,是笔者一直珍藏的最好的泛型学习笔记. 一.面向过程的时代 我们先 ...