/*
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. WCF使用泛型方法的问题

    public IList getModelList(string type, string SQL, List<string> list){ try { IList Mlist = new ...

  2. php学习笔记:读取文档的内容,利用php修改文档内容

    直接上代码 <?php /** * Created by PhpStorm. * User: Administrator * Date: 2016/9/10 0010 * Time: 20:27 ...

  3. 【Effective Java】2、构造参数过多的时候

    package cn.xf.cp.ch02.item2; /** * * 功能:当我们的构造参数有很多,超出可控范围的时候,用build模式 时间:下午8:25:05 文件:NutritionFact ...

  4. SQL Server SQL语句执行顺序

    执行顺序: 1.FROM:对FROM子句中前两个表执行笛卡尔积生成虚拟表vt1 2.ON:对vt1表应用ON筛选器只有满足 为真的行才被插入vt2 3.OUTER(join):如果指定了 OUTER ...

  5. mac下eclipse的svn(即svn插件)怎么切换账号?

    以mac os x为例(Unix/Linux类似) 打开命令行窗口,即用户的根目录(用户的home目录) cd ~ 即可进入home目录. 执行命令 ls -al 会列出home目录下的所有文件及文件 ...

  6. Jaxb解析xml准换为javabean

    先说下这个的背景吧,前些日子,有个以前的小同事说刚接触webservice,想解析下xml,记得我学的时候还是dom4j,sax的解析方式,最近看别人的代码用的jaxb的方式,觉得注解起来很简练,所以 ...

  7. XML的文档声明

    1.XML的文档声明 <?xml version="1.0" encoding="utf-8"?> 文档声明必须写在第一行第一列 属性: versi ...

  8. Study Tips

    1. 100% width divs not spanning entire width of the browser in webkit. Even Body can not span the en ...

  9. ABAP指针

    1. 什么是ABAP指针:在ABAP里面,field symbol就相当于c语言的指针.如果你定义并且分配了相应的结构或者变量给它,其实它就指向这个结构或者变量的地址,如果修改了field symbo ...

  10. Objective-C之优雅的命名

    There are only two hard things in Computer Science: cache invalidation and naming things.在计算机科学中只有两件 ...