BZOJ 1629: [Usaco2007 Demo]Cow Acrobats】的更多相关文章

Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet prevent them from tightrope walking and swinging from the trapeze (and their last attempt at firing a cow out of a ca…
仿佛学到了贪心的新姿势-- 考虑相邻两头牛,交换它们对其他牛不产生影响,所以如果交换这两头牛能使这两头牛之间的最大值变小,则交换 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=50005; int n,ans=-1e9,sum[N]; struct qwe { int x,y; }a[N]; inline bool cmp(const qw…
http://www.lydsy.com/JudgeOnline/problem.php?id=1629 这题我想了很久都没想出来啊... 其实任意两头相邻的牛交换顺序对其它牛是没有影响的.. 那么我们考虑哪个在前..(假设现在是待交换的是 a和b,a<b) 当重b-力a < 重a-力b时,就不需交换,否则交换.. 这个贪心自己想想就懂了的.. #include <cstdio> #include <cstring> #include <cmath> #in…
1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 601  Solved: 305[Submit][Status] Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet pre…
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1332 题意: 有n头牛在“叠罗汉”. 第i头牛的体重为w[i],力量为s[i]. 一头牛的压扁程度 = 它上面所有牛的体重之和 - s[i] 所有牛的总压扁程度 = 所有牛中最大的那个压扁程度 问你总压扁程度最小为多少. 题解: 贪心. 套路: 选取最小的一个单元——相邻的两头牛,进行贪心策略的局部证明. 贪心策略: 假设最左边为顶部,最右边为底部. 从左往右分别编号0...n-1.…
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1629 [算法] 贪心 考虑两头相邻的牛 , 它们的高度值和力量值分别为ax , ay , bx , by 我们发现 , 当ax + ay < bx + by时 , x排在前面比y排在前面更优 也就是说 , 当序列中有相邻的牛使得ax + ay >= bx + by时 , 可以通过交换两头牛使得答案更优 综上 , 按牛的(高度值 + 力量值)以关键字升序排序 , 即可 时间复杂度…
直接floyd.. ---------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>   #define rep( i , n ) for( int i = 0 ;  i < n ; ++i ) #define clr(…
这道题和蔡大神出的今年STOI初中组的第二题几乎一模一样... 先跑一遍最短路 , 再把所有边反向 , 再跑一遍 , 所有点两次相加的最大值即为answer ----------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #in…
题目 1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 491  Solved: 362[Submit][Status] Description     农场有N(1≤N≤1000)个牛棚,每个牛棚都有1只奶牛要参加在X牛棚举行的奶牛派对.共有M(1≤M≤100000)条单向路连接着牛棚,第i条踣需要Ti的时间来通过.牛们都很懒,所以不管是前去X牛棚参加派对还是返回住所,她们都采用了用时最少的…
[Usaco2007 Jan]Cow School牛学校 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 175  Solved: 83[Submit][Status][Discuss] Description Bessy 正在上学并且分数还不错. 她考了N (一个数据中1 <= N <= 50,000, 其余数据 1 <= N <= 50,00) 次试,每次考试得分为T_i, 满分为P_i(0 <= T_i <= P_i &…