BZOJ 1629 Usaco Cow Acrobats

感觉就是一道贪心的题目,但是苦于没法下手。
在瞎写了几组数据之后,猜了一个结论。A1-B1<A2-B2
在看了看题解之后,发现自己好菜啊。

首先由两个前提条件
1. 两头牛调换顺序,并不会影响后面牛的计算。
2. 两头牛的顺序会影响答案.

所以 我们设 A,B为两个相邻的牛
需要满足 Ax-By < Bx-Ay 的关系 才会使答案变小

#include <cstdio>
#include <algorithm>
 
struct node{
    long long  x,y;
}now[50005];
 
int n;
bool CMP(const node &a,const node &b){
    return a.x-b.y<b.x-a.y;
}
 
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld%lld",&now[i].x,&now[i].y);
    std::sort(now+1,now+1+n,CMP);
    long long tot = 0,Max=-23333333333;
    for(int i=1;i<=n;i++){
        Max = std::max(Max,tot-now[i].y);
        tot+=now[i].x;
    }  
    printf("%lld\n",Max);
    return 0;
}
时间: 2024-10-07 21:52:20

BZOJ 1629 Usaco Cow Acrobats的相关文章

【BZOJ 1629】 [Usaco2007 Demo]Cow Acrobats

1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 657  Solved: 331 [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 p

1629: [Usaco2007 Demo]Cow Acrobats

1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1023  Solved: 531[Submit][Status][Discuss] Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofe

POJ3045 Cow Acrobats —— 思维证明

题目链接:http://poj.org/problem?id=3045 Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5713   Accepted: 2151 Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. The

[BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)

[BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given

bzoj1629[Usaco2007 Demo]Cow Acrobats*

bzoj1629[Usaco2007 Demo]Cow Acrobats 题意: n头牛,每天牛都有体重与力量值.它们玩叠罗汉的游戏,每个牛的危险值等于它上面的牛的体重总和减去它的力量值,求所有方案中危险值最大的最小. 题解: 贪心.第i头牛比第j头牛高当且仅当i的重量-j的力量<j的重量-i的力量. 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn

Cow Acrobats(贪心)

Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3686   Accepted: 1428 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 tig

[USACO2005][POJ3045]Cow Acrobats(贪心)

题目:http://poj.org/problem?id=3045 题意:每个牛都有一个wi和si,试将他们排序,每头牛的风险值等于前面所有牛的wj(j<i)之和-si,求风险值最大的牛的最小风险值 分析:这就是noip2012 T2的来源= =只不过这里是加,noip里是乘 不妨设所有牛都按最优顺序排好了,考虑相邻的两头牛i和i+1,如果交换他们的位置,那么对前面和后面的结果都无影响,只是他们两个的风险值变化了(变大了),于是我们可以得到这个时候i和i+1的关系 设w1+w2+...+wi-1

POJ 3045 Cow Acrobats (想法题)

题目链接:POJ 3045 Cow Acrobats 题意:有n只牛叠罗汉,危险指数的计算是 该层牛以上的牛重量总和减去这层牛的强度,求使最大的危险指数中的最小值. 思路:根据w+s排序,最大的在最下面,道理很简单,危险指数: sum-(w+s),(sum该层牛以上的牛重量总和). AC代码: #include<stdio.h> #include<string.h> #include<algorithm> #define ll __int64 using namespa

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