/*
ID: vincent63
LANG: C
TASK: milk2
*/
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
struct time{
int begin;
int end;
int len;
}; void sort(struct time t[],int n){
int i,j;
struct time temp;
for(i=;i<n;i++){
for(j=i;j<n;j++){
if(t[j].begin<t[i].begin){ temp.begin=t[i].begin;
temp.end=t[i].end;
temp.len=t[i].len; t[i].begin=t[j].begin;
t[i].end=t[j].end;
t[i].len=t[j].len; t[j].begin=temp.begin;
t[j].end=temp.end;
t[j].len=temp.len; }
}
}
}
void merge(struct time t[],int n){
int i,j;
for(i=,j=;j<n;i++,j++){
if(t[i].end<t[j].begin){
continue;
}else if(t[i].end>=t[j].begin&&t[i].end<=t[j].end){
t[i].end=t[j].end;
t[j].begin=t[i].begin;
t[i].len=t[i].end-t[i].begin;
t[j].len=t[j].end-t[j].begin; }else if(t[i].end>t[j].end){
t[j].begin=t[i].begin;
t[j].end=t[i].end;
t[j].len=t[j].end-t[j].begin;
}
}
}
int findmax(struct time t[],int n){
int i,j;
int max=;
for(i=;i<n;i++){
if(t[i].len>max){
max=t[i].len;
}
}
return max;
}
int findmin(struct time t[],int n){
int temp[n];
int i;
int max=; for(i=;i<n-;i++){
temp[i]=t[i+].begin-t[i].end;
if(temp[i]>&&temp[i]>max){
max=temp[i];
}
} return max;
} int main () {
FILE *fin = fopen ("milk2.in", "r");
FILE *fout = fopen ("milk2.out", "w"); int n,i;
char buf[];
char buf2[]; fgets(buf,,fin);
n=atoi(buf); struct time t[*n]; for(i=;i<n;i++){
int b,e;
fgets(buf2,,fin);
sscanf(buf2,"%d %d",&b,&e);
t[i].begin=b;
t[i].end=e;
t[i].len=e-b;
} sort(t,n);
merge(t,n); int max; max=findmax(t,n);
int min;
min=findmin(t,n); char res[];
sprintf(res,"%d ",max);
fputs(res,fout);
sprintf(res,"%d\n",min);
fputs(res,fout);
printf("%d %d\n",max,min);
return ;
}

USACO section1.2 Miking cows的更多相关文章

  1. USACO Section1.2 Milking Cows 解题报告

    milk2解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  2. NC25136 [USACO 2006 Ope B]Cows on a Leash

    NC25136 [USACO 2006 Ope B]Cows on a Leash 题目 题目描述 给定如图所示的若干个长条.你可以在某一行的任意两个数之间作一条竖线,从而把这个长条切开,并可能切开其 ...

  3. USACO Section 1.2PROB Miking Cows

    贪心做过去,先对每个时间的左边点进行排序,然后乱搞,当然线段树也可以做 /* ID: jusonal1 PROG: milk2 LANG: C++ */ #include <iostream&g ...

  4. USACO Section1.3

    section1.2主要包括5道题和1个编程知识介绍.下面对这6部分内容进行学习. Complete Search 这个翻译成枚举搜索或者穷举搜索.主要用于当写代码时间不够用而且不用考虑程序的效率问题 ...

  5. USACO Section1.2

    section1.1主要包括四道题和两个编程知识介绍.下面将对这6个部分内容进行学习. Your Ride Is Here 这道题没什么难度,读懂题目意思就行:把两个字符串按照题目要求转换成数字,然后 ...

  6. USACO Section1.1

    本系列博客主要学习和记录USACO的相关代码和总结,附上我的github地址. 什么是USACO USACO全称是The USA Computing Olympiad,主要目的是从美国高中生中选出代码 ...

  7. 【bzoj2591】[Usaco 2012 Feb]Nearby Cows 树形dp

    题目描述 Farmer John has noticed that his cows often move between nearby fields. Taking this into accoun ...

  8. USACO Section1.5 Prime Palindromes 解题报告

    pprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  9. USACO Section1.4 Mother's Milk 解题报告

    milk3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

随机推荐

  1. sql server 2008出现评估期已过的问题

    我的sql server2008用来半年吧,那天的昨天还能用,到了180天后,就不能用了,具体问题如下: 出了这个问题后,就打不开sql server了 解决方法: 1.打开安装中心,升级sql se ...

  2. jQuery: jquery.json.js

    http://api.jquery.com/jQuery.parseJSON/ http://www.json.org/json-zh.html http://fineui.codeplex.com/ ...

  3. 一个小笔记(7):EN_1

    For nearly ten years, the Unified Modeling Language(UML) has been the industry standard for visualiz ...

  4. ComboBox的联动(三层架构)

    需求:根据年级下拉框的变化使得科目下拉框绑定次年级下对应有的值 我们用三层架构的模式来实现 1.我们想和数据库交互,我们首先得来先解决DAL数据库交互层 01.获得年级下拉框的数据 在GradeDAL ...

  5. 优化磁盘I/O

    管理I/O,避免过度地寻道可以让硬盘更快.顺序I/O和随机I/O之间的性能差异随便就可以达到40:1,可能更多.这在数据库服务器中尤其重要,因为数据库的日志是以顺序格式写的.选择合适的硬件,合理地配置 ...

  6. C# Winform 窗体美化

    using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using Sys ...

  7. Rendering Problems: No Android SDK found. Please configure an Android SDK. 怎解决?

    Rendering Problems No Android SDK found. Please configure an Android SDK.

  8. PHP控制前台弹出对话框

    应用场景: 微信授权登录过程中,需要用户确认,故衍生此需求: 相应的逻辑不放在前端的原因是,此部分逻辑属于偏功能业务,所以放在后端,方便统一管理. 解决办法: 通过php echo出javascrip ...

  9. BINARY SEARCH in read table statement

    1.for standard table, it must be sorted by search key. 2.for sorted table , binary search is used au ...

  10. Mybatis学习记录(三)----理解SqlMapConfig.xml文件

    SqlMapConfig.xml mybatis的全局配置文件SqlMapConfig.xml,配置内容如下: properties(属性) settings(全局配置参数) typeAliases( ...