USACO Section 1.1: Milking Cows
2014-03-13 14:34
501 查看
/* ID: leetcod3 PROG: milk2 LANG: C++ */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> #include <cmath> #include <list> #include <cstdio> #include <cstdlib> #include <limits> #include <stack> using namespace std; ofstream fout ("milk2.out"); ifstream fin ("milk2.in"); int main() { int N; fin >> N; vector<pair<int, int> > input(N); for (int i = 0; i < N; i++) fin >> input[i].first >> input[i].second; sort(input.begin(), input.end()); //for (int i = 0; i < input.size(); i++) cout << input[i].first << " " << input[i].second << endl; int left = input[0].first; int right = input[0].second; int a = right - left; int b = 0; for (int i = 1; i < N; i++) { if (input[i].first <= right) { right = max(right, input[i].second); a = max(a, right - left); } else { b = max(b, input[i].first - right); left = input[i].first; right = input[i].second; } } fout << a << " " << b << endl; return 0; }
相关文章推荐
- USACO Section 1.1 题解
- USACO Section 1.1: Greedy Gift Givers
- USACO Milking Cows
- USACO 之 Section 1.1 Ad Hoc Problems (已解决)
- USACO - Chapter1 Section 1.1 - Greedy Gift Givers
- USACO-Section1.1 Greedy Gift Givers
- USACO Section 5.1 Fencing the Cows(凸包)
- Wewe带你看代码 --USACO Section1.1
- usaco Milking Cows (贪心)
- usaco Milking Cows
- USACO Section 1.1-3 Friday the Thirteenth
- USACO Section 5.1 Fencing the Cows - 凸包模板题~~
- USACO 之 Section 1.1 Ad Hoc Problems
- USACO - Chapter1 Section 1.1 - Friday the Thirteenth
- USACO-Section1.1 Your Ride Is Here [模拟]
- USACO-Section1.1 Greedy Gift Givers[...]
- USACO:Section 1.1 Greedy Gift Givers
- USACO Section 1.1 Broken Necklace 解题报告
- usaco Milking Cows
- USACO Training Section1.1