Ac简单题-Milking Cow
2014-05-30 23:03
393 查看
链接 http://acm.sjtu.edu.cn/OnlineJudge/problem/1262
1262. Milking Cow
Description
瓦特尔,阿隆索,汉密尔顿在F1上海站进行比赛,每人必须进维修站更换轮胎一次(谁出的无聊规定?!),而且只能进维修站一次。阿隆索在20秒进站换胎,一直到90秒出站。瓦特尔在60秒开始进站,在 130秒结束。汉密尔顿在160秒开始220秒结束。期间最长的至少有一个车手在维修区的连续时间为110秒(从20秒到130秒),而最长的无人在维修区的连续时间(从有人进维修站开始一直到出维修站)为30秒(从130秒到160秒)。
假设现在又进行了一场有N个车手的比赛,你的任务是编一个程序,读入一个有N个车手(1 <= N <= 5000)进N次站的工作时间列表,计算以下两点(均以秒为单位):
最长至少有一人在维修站内的时间段。
最长的无人在维修站的时间段。(从有人进站开始算起)
Input Format
第1行:一个整数N。第2至第N+1行:每行两个小于1000000的非负整数,表示一个车手的进站时刻与出站时刻。
Output Format
一行,两个整数,即题目所要求的两个答案。
Sample Input
3 200 900 600 1300 1600 2200
Sample Output
1100 300
#include <iostream> using namespace std; struct timeT { int start,end; bool still_in;//if it is true means that not yet , false }; int max(int a,int b) { if(a>b){return a;} return b; } int min(int a,int b) { if(a<b){return a;} return b; } int main() { int n,newstart,newend,sum,count=0,max_havecar=0,max_nocar=0; timeT car_time[5000],temp,*p; cin>>n; sum=n; for(int i=0;i<n;i++) { cin>>car_time[i].start>>car_time[i].end; car_time[i].still_in=true; } for(int i=0;i<n;i++) { if(car_time[i].still_in==false)continue; for(int j=i+1;j<n;j++) { if(car_time[j].still_in==false)continue; if(car_time[i].end<car_time[j].start||car_time[i].start>car_time[j].end) { continue; } else { newstart=min(car_time[i].start,car_time[j].start); newend=max(car_time[i].end,car_time[j].end); temp.start=newstart; temp.end=newend; temp.still_in=true; car_time[j]=temp; car_time[i].still_in=false; sum--; break; } } } p=new timeT[sum+1]; for(int i=0;i<n;i++) { if(car_time[i].still_in==true) { p[count]=car_time[i]; count++; } } for(int i=0;i<sum-1;i++) { for(int j=i+1;j<sum;j++) { if(p[i].start>p[j].start) { temp=p[i]; p[i]=p[j]; p[j]=temp; } } } for(int i=0;i<sum;i++) { count=p[i].end-p[i].start; if(count>max_havecar)max_havecar=count; } for(int i=0;i<sum-1;i++) { count=p[i+1].start-p[i].end; if(count>max_nocar)max_nocar=count; } cout<<max_havecar<<" "<<max_nocar; delete []p; }
相关文章推荐
- 【HDU4313】Matrix 多校 解题报告+AC代码+思路+算法正确性证明,此为Kruskal贪心简单版本,恶心版本稍后放出【目标达成 0.2%】
- 简单的数论题目zju1652(不知道有没有AC,因为我在zju上没帐号)PKU上没有
- HDOJ 4057 - Rescue the Rabbit 简单的AC自动机+状态压缩DP
- HDU 3340 Rain in ACStar 线段树+简单几何?
- POJ 3784 Running Median简单版本可AC
- hdu2037 今年暑假不AC (简单贪心)
- AC自动机算法简单介绍
- hdu 1686 Oulipo(简单KMP)只不过比赛的时候用了string.一直超时,改成char就一遍AC,纠结。。。
- HDU 2222 最简单的AC自动机套模板应用
- Linux下使用automake autoconf autoscan aclocal简单介绍
- Acdream Xor 简单数学
- HDU 2037 今年暑假不AC(简单贪心)
- uva10474 简单排序查找 一次AC
- HDOJ 2037 今年暑假不AC (简单贪心)
- 杭电ACM 今年暑假不AC 2037(关于最简单的贪心算法)
- Poj 1204 简单AC自动机
- poj 1979 简单深搜 一次 ac 不解释
- hdu 2457 ac自动机+简单dp
- YII2.0 AcriveRecord的简单使用
- acdream 1025 简单dp