题目大意: 有N (2 ≤ N ≤ 100,000) 头牛偷吃花 将牛赶回牛棚需Ti minutes (1 ≤ Ti ≤ 2,000,000) 每头牛每分钟能吃Di (1 ≤ Di ≤ 100) 朵花 则赶牛的来回需2*Ti minutes (Ti to get there and Ti to return) Input * Line 1: A single integer N * Lines 2..N+1: Each line contains two space-separated inte…
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 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 retur…
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 --------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>   #define rep( i ,…
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 493  Solved: 310[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 retur…
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 885  Solved: 575[Submit][Status][Discuss] Description Farmer John went to cut some wood and left N (2 <= N <= 100,000) cows eating the grass, as usual. When…
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵花.求一个弄走牛的顺序,使得这些牛破坏最少的花. 注释:$1\le n \le 10^5$. 想法:贪心. 两头牛i和j. 只考虑这两头牛的位置. 如果i在j前面,拉走i的时候j会造成$2t_i*atk_j$朵花.反之同理. 比较两者谁大就放在前面. 在cmp中这样写就行了. 最后,附上丑陋的代码.…
P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 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 cluster of cows was in his garden eating his beautiful…
Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7812   Accepted: 3151 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 ho…
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4930   Accepted: 1965 Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When…
P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并没有影响. 我们设距离为$a_{i}$,每分钟贡献$b_{i}$ $a_{1}$        $b_{1}$ $a_{2}$        $b_{2}$ 先抓第一头的代价:$a_{1}b_{1}+2a_{1}b_{2}+a_{2}b_{2}$ 先抓第二头的代价:$a_{2}b_{2}+2a_{2…
Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4418   Accepted: 1785 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 ho…
Description 约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的.他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草.可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园, 正在啃食他精心培育的花朵!约翰要立即采取行动,挨个把它们全部关回牛棚. 约翰牵走第 i 头奶牛需要 T i 分钟,因为要算来回时间,所以他实际需要 2 · T i 分钟.第 i 头奶牛 如果还在花园里逍遥,每分钟会啃食 Di 朵鲜花.但只要约翰抓住了它,开始牵走它的那刻开始,就 没法吃花了.请帮…
洛谷 P2878 [USACO07JAN]保护花朵Protecting the Flowers 洛谷传送门 JDOJ 1009: 护花 JDOJ传送门 Description FJ出去砍木材去了,把N(2<=N<=100,000)头牛留在家中吃草,当他回来的时候,发现奶牛们都跑到花园里吃花去了,为了减少损失,FJ打算把牛移到牛棚中去. 每头牛的位置离牛棚需要Ti分钟(1<=Ti<=2,000,000),而且在等待被移走的过程中,每分钟破坏Di(1<=Di<=100)朵花…
Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有味地吃着FJ种的美丽的花!为了减少后续伤害,FJ决定立即采取行动:运输每头牛回到自己的牛棚. 每只奶牛i在离牛棚Ti(1 ≤ Ti ≤ 2,000,000) 分钟路程的地方,每分钟吃掉Di(1 ≤ Di ≤ 100)朵花.FJ使尽浑身解数,也只能一次带回一头奶牛.弄回一头奶牛i需要2*Ti分钟(来回…
Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11402   Accepted: 4631 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 h…
NC25043 [USACO 2007 Jan S]Protecting the Flowers 题目 题目描述 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 cluster of cows was in his garden eating hi…
题目描述 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,…
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…
http://www.lydsy.com/JudgeOnline/problem.php?id=1634 贪心.. 我们发现,两个相邻的牛(a和b)哪个先走对其它的牛无影响,但是可以通过 a的破坏花×b的时间 和 b的破坏花×a的时间 可以判断哪个先走. 那么可以应用到所有牛上.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iost…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1634 题意: 约翰留下他的N只奶牛上山采木.可是,当他回来的时候,他看到了一幕惨剧:牛们正躲在他的花园里,啃食着他心爱的美丽花朵! 为了使接下来花朵的损失最小,约翰赶紧采取行动,把牛们送回牛棚. 第i只牛所在的位置距离牛棚t[i](1 <= t[i] <= 2000000)分钟的路程,而在约翰开始送她回牛棚之前,她每分钟会啃食e[i](1 <= e[i] <= 100)朵鲜…
因为交换相邻两头牛对其他牛没有影响,所以可以通过交换相邻两头来使答案变小.按照a.t*b.f排降序,模拟着计算答案 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=100005; int n; long long ans,sum; struct qwe { int v,t; }a[N]; bool cmp(const qwe &a,c…
将 0 变为 -1 , 则只需找区间和为 0 , 即前缀和相同的最长区间 , 记录一下每个前缀和出现的最早和最晚的位置 , 比较一下就 OK 了 ------------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostr…
题目描述 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 cluster of cows was in his garden eating his beautiful flowers. Wanting to minimize the subsequent…
http://www.lydsy.com/JudgeOnline/problem.php?id=1637 很神思想.. 前缀和应用到了极点... 我们可以发现当数量一定时,这个区间最前边的牛的前边一个牛的前缀和等于这个区间最后边的牛的前缀和..(将0的牛变成-1,然后维护前缀和) 然后扫过去就行了... orz #include <cstdio> #include <cstring> #include <cmath> #include <string> #i…
一.题面 POJ3262 二.分析 这题要往贪心上面想应该还是很容易的,但问题是要证明为什么比值关系就能满足. 可以选择几个去分析,入1-6  与 2-15  和 1-6 与2-5 和 1-6 与 2- 12. 三.AC代码 #include <cstdio> #include <iostream> #include <algorithm> #include <fstream> using namespace std; ; struct Cow { int…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1637 题意: Farmer John 决定给他的奶牛们照一张合影,他让 N (1 ≤ N ≤ 50,000) 头奶牛站成一条直线,每头牛都有它的坐标x(0 <= x <= 10^9)和种族(0或1). 他只给一部分牛照相,并且这一组牛的阵容必须是“平衡的”. 平衡的阵容,指的是在一组牛中,种族0和种族1的牛的数量相等. 区间的大小为区间内最右边的牛的坐标减去最做边的牛的坐标. 请算出最…
题目描述 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 cluster of cows was in his garden eating his beautiful flowers. Wanting to minimize the subsequent…
保护花朵 题目大意:就是农夫有很多头牛在践踏花朵,这些牛每分钟破坏D朵花,农夫需要把这些牛一只一只运回去,这些牛各自离牛棚都有T的路程(有往返,而且往返的时候这只牛不会再破坏花),问怎么运才能使被践踏的花最少? 一开始我做这道题的时候,用的是贪婪算法,然后我是这样做的,我先把D按照逆序排一遍,然后如果D相等的时候,再按T的顺序排序,然后两两比较看最小,就选谁,自以为是一个非常好的思路,但是果断WA了. 其实你要问我为什么这个思路?我一开始是这么想的,我想尽量让D大的元素出列,然后让T尽量少影响最…
http://poj.org/problem?id=3262 开始一直是理解错题意了!!导致不停wa. 这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛需要的时间和牛在花园每分钟吃多少花朵,问你怎么安排让损失最小. 这题单独按time和eat排序都不行,得按它们的比率来排,如果是选择eat/time  则从大到小排,time/eat则从小到大排,但是不会严格证明. #include <iostream> #include <cstdio&g…
题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛b所处位置为, 交换前 ....(ta, da) (tb, db).... 交换后 ....(tb, db) (ta, da).... 设此前已消耗的时间为x,那么交换前消耗的草:x*da + (x+ta)*db 交换后消耗的草:x*db + (x+tb)*da 除非交换后的消耗相比交换前的小才交换…