USACO Section 1.2PROB Miking Cows

贪心做过去,先对每个时间的左边点进行排序,然后乱搞,当然线段树也可以做

/*
ID: jusonal1
PROG: milk2
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
struct node{
    int left;
    int right;
    bool operator<(const node& T)const{
        return left < T.left;
    }
};
int n;
const int maxn = 5000 + 100;
node cow[maxn];
int main () {
    freopen("milk2.in","r",stdin);
    freopen("milk2.out","w",stdout);
    scanf("%d",&n);
    for(int i = 1;i <= n;++i) scanf("%d%d",&cow[i].left,&cow[i].right);
    sort(cow + 1,cow + 1 + n);
    int cont_time = cow[1].right - cow[1].left,idle_time = 0;
    int start = 0,end = 0;
    int blank_sum = 0;
    start = cow[1].left;
    end   = cow[1].right;
    for(int i = 1;i <= n;++i){
        if(cow[i].left > end ){
            idle_time = max(idle_time,cow[i].left - end);
            start = cow[i].left;
            end   = cow[i].right;
        }
        else if(cow[i].right > end){
            end = cow[i].right;
        }
        cont_time = max(cont_time,end - start);
    }
    printf("%d %d\n",cont_time,idle_time);
    return 0;
}
时间: 2024-08-05 07:04:56

USACO Section 1.2PROB Miking Cows的相关文章

USACO Section 1.2PROB Transformations

挺有趣的一道题,呵呵,不算难 /* ID: jusonal1 PROG: transform LANG: C++ */ #include <iostream> #include <fstream> #include <string> #include <cstdio> #include <algorithm> #include <map> #include <cstring> using namespace std; co

USACO Section 2.1 Healthy Holsteins

/* ID: lucien23 PROG: holstein LANG: C++ */ #include <iostream> #include <fstream> #include <vector> using namespace std; bool compFun(int x, int y) { int temp, i = 0; while (true) { temp = 1 << i; if (temp&x > temp&y) {

USACO Section 2.2 Party Lamps

/* ID: lucien23 PROG: lamps LANG: C++ */ /* * 此题的技巧之处就是需要注意到任何button只要按下2的倍数次就相当于没有按 * 所以其实只需要考虑4个按钮,每个按钮是否被有效按下过一次就好 * 直接使用枚举法,一共只有2^4=16种情况 * 对于每种情况需要知道被按下的有效次数(也就是被按下过的按钮数),必须满足 * (C-有效次数)%2=0才行,这样其他次数才能视为无效 * 然后验证各种情况是否符合要求,将符合要求的情况按序输出即可 */ #inc

USACO Section 2.2 Runaround Numbers

/* ID: lucien23 PROG: runround LANG: C++ */ #include <iostream> #include <fstream> #include <cstring> using namespace std; int main() { ifstream infile("runround.in"); ofstream outfile("runround.out"); if(!infile || !

USACO Section 2.2 Preface Numbering

/* ID: lucien23 PROG: preface LANG: C++ */ #include <iostream> #include <fstream> #include <string> #include <map> using namespace std; int main() { ifstream infile("preface.in"); ofstream outfile("preface.out")

[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

USACO Section 5.1 Fencing the Cows(凸包)

裸的凸包..很好写,废话不说,直接贴代码. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #define rep(i,r) for(int i=0;i<r;i++) using namespace std; const int maxn=10000+5; struct P { double x,y; P(do

USACO Section 4.2 The Perfect Stall

二分图的最大匹配.我是用最大流求解.加个源点s和汇点t:s和每只cow.每个stall和t 连一条容量为1有向边,每只cow和stall(that the cow is willing to produce milk in )也连一条容量为1的边.然后就用ISAP. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector>

USACO Section 2.1 Sorting a Three-Valued Sequence

/* ID: lucien23 PROG: sort3 LANG: C++ */ #include <iostream> #include <fstream> #include <vector> #include <algorithm> using namespace std; void exchange(int nums[], int begin, int end, int N, int x); int sum = 0; int main() { ifst