/*
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. 1. windows环境安装Node.js

    1. 下载 地址: https://nodejs.org/en/ 2. 下载最新版本v6.1.0 Currrent

  2. Ahjesus获取自定义属性Attribute或属性的名称

    1:设置自己的自定义属性 public class NameAttribute:Attribute { private string _description; public NameAttribut ...

  3. Android:TextView 自动滚动(跑马灯) (转)

    Android:TextView 自动滚动(跑马灯)       TextView实现文字滚动需要以下几个要点: 1.文字长度长于可显示范围:android:singleLine="true ...

  4. [Architecture Design] 3-Layer基础架构

    [Architecture Design] 3-Layer基础架构 三层式体系结构 只要是软件从业人员,不管是不是本科系出身的,相信对于三层式体系结构一定都不陌生.在三层式体系结构中,将软件开发所产出 ...

  5. 用单例模式封装常用方法 utils class v1.0

    utils class v1.0:The common methods used in our JS are included. * by sarah on 2016/01/28 var utils ...

  6. Win10安装framework3.5

    .NET少不了framewrok,其版本也比较多,默认情况下win7及上版本没有安装framework3.5,但有些软件又需要它,比如arcgis软件在安装时会检测是否存在3.5,如果没有,将不会正常 ...

  7. SharePoint 更新文档库文档标题(Title)字段

    前言:记录下写代码中遇到的小问题,帮同事写一个批量更新文档库标题字段的小程序,本来以为就Update一下就可以了,10分钟可以搞定.结果10分钟过去了,代码写好了,执行起来不报错,调试也没问题,只是要 ...

  8. 转:Eclipse 一直不停 building workspace... 完美解决总结

    原文地址: Eclipse 一直不停 building workspace... android开发论坛 juapk 完美解决总结 一.产生这个问题的原因多种 1.自动升级 2.未正确关闭  3.ma ...

  9. IOS中把字符串加密/IOS中怎么样MD5加密/IOS中NSString分类的实现

    看完过后,你会学到: 1学习IOS开发中的分类实现, 2以及类方法的书写, 3以及字符串的MD5加密/解密. ---------------------------wolfhous---------- ...

  10. linux下安装mysql手记

    安装mysql 下载mysql-standard-4.1.8-pc-linux-i686.tar.gz文件到目录/usr/local/下 # groupadd mysql   //添加mysql用户组 ...