USACO milking cows
来源:互联网 发布:好看的网络剧霸道总裁 编辑:程序博客网 时间:2024/04/30 23:35
Description:
Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer begins milking his cow at time 300 (measured in seconds after 5 am) and ends at time 1000. The second farmer begins at time 700 and ends at time 1200. The third farmer begins at time 1500 and ends at time 2100. The longest continuous time during which at least one farmer was milking a cow was 900 seconds (from 300 to 1200). The longest time no milking was done, between the beginning and the ending of all milking, was 300 seconds (1500 minus 1200).
Your job is to write a program that will examine a list of beginning and ending times for N (1 <= N <= 5000) farmers milking N cows and compute (in seconds):
- The longest time interval at least one cow was milked.
- The longest time interval (after milking starts) during which no cows were being milked.
PROGRAM NAME: milk2
INPUT FORMAT
Line 1: The single integer Lines 2..N+1: Two non-negative integers less than 1,000,000, respectively the starting and ending time in seconds after 0500SAMPLE INPUT (file milk2.in)
3300 1000700 12001500 2100
OUTPUT FORMAT
A single line with two integers that represent the longest continuous time of milking and the longest idle time.SAMPLE OUTPUT (file milk2.out)
900 300
#include <bits/stdc++.h> using namespace std; pair<int,int> a[10005],b[10005]; void debug(int cnt){ for (int i=0;i<cnt;i++){ cout<<i<<" "<<"Event "; cout<<b[i].second<<" "<<b[i].first<<endl; } } int main() { freopen("milk2.in","r",stdin); freopen("milk2.out","w",stdout); int n; while (scanf("%d",&n)==1) { int cnt=0; for (int i=0;i<n;i++){ scanf("%d%d",&a[i].first,&a[i].second); } sort(a,a+n); b[cnt++]=a[0]; for (int i=1;i<n;i++){ int flag=0; for (int ii=0;ii<cnt;ii++){ if (a[i].first<=b[ii].second){ b[ii].second=max(b[ii].second,a[i].second); b[ii].first=min(b[ii].first,a[i].first); flag=1; break; } } if (!flag) b[cnt++]=a[i]; } //debug(cnt); if (cnt==1) printf("%d %d\n",b[cnt-1].second-b[cnt-1].first,0); else{ int mxt=0,mxl=0; for (int i=0;i<cnt;i++){ mxl=max(b[i+1].first-b[i].second,mxl); mxt=max(b[i].second-b[i].first,mxt); } printf("%d %d\n",mxt,mxl); } } return 0; }
- Milking Cows(USACO)
- USACO 1.2-Milking Cows
- usaco 1.2:Milking Cows
- [USACO] Milking Cows
- usaco Milking Cows
- USACO 1.2 Milking Cows
- [USACO]Milking Cows
- usaco Milking Cows 报告
- usaco:Milking Cows
- USACO-Milking Cows
- USACO--1.2 Milking Cows
- USACO 1.2 Milking Cows
- USACO Milking Cows
- USACO Milking Cows
- USACO Milking Cows(模拟)
- USACO Milking Cows(greedy)
- USACO 1.1 Milking Cows
- USACO milking cows
- 一个『瘦猴』对产品的一点看法
- 现代软件的含义
- 【树状数组】[CodeForces - 341D]Iahub and Xors
- 0.0
- 安卓 dex 通用脱壳技术研究(四)
- USACO milking cows
- js之异常捕捉
- 快速幂取模
- java当中float以及double数据类型的掌握
- [LeetCode] Binary Tree Inorder Traversal
- 2015年作为一名Android需要知道的
- poj3259
- HTTP Status 500 -(struts2整合进spring2.5和hibernate3.3)
- 爱奇艺笔试编程题 (学习之旅)