/*
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交叉表

    之前做货品横向展示时,有看到评论说用到交叉表. 公司最近需要给订单表做一个数据汇总的功能,同事给到一个参考SQL select * from (select COUNT(1) as 已锁定 from ...

  2. 【C#进阶系列】04 类型基础

    关于System.Object 所有类型都从System.Object派生而来. System.Object的公共方法中ToString()一般是返回对象的类型的全名,只有Int32这些类型将其重写后 ...

  3. C# 发邮件

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  4. PPP模式下的融资结构优化

    PPPcode{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && d ...

  5. 探索HashMap实现原理及其在jdk8数据结构的改进

    因为网上已经太多的关于HashMap的相关文章了,为了避免大量重复,又由于网上关于java8的HashMap的相关文章比较少,至少我没有找到比较详细的.所以才有了本文. 本文主要的内容: 1.Hash ...

  6. mac下用ruby安装sass && webstorm下给scss文件添加watch

    1.安装rvm 先安装 [Xcode](http://developer.apple.com/xcode/) 开发工具,它将帮你安装好 Unix 环境需要的开发包 sudo curl -L https ...

  7. ASP.NET MVC 微信公共平台开发之 微信接入

    ASP.NET MVC 接入微信公共平台 申请微信公共账号 既然要接入微信公共平台,微信公共号是必须的(当然如果只是测试的话也可以申请微信公共平台接口测试账号),来这里微信公共平台 申请微信公共号(注 ...

  8. OC登陆界面登陆按钮动画

    1.原作者:@entotsu 1.1 原作者连接:https://github.com/entotsu/TKSubmitTransition 2.使用: import "HyTransiti ...

  9. Silverlight项目笔记2:.svc处理程序映射缺失导致的WCF RIA Services异常

    在确定代码.编译结果和数据库都正常的情况下,无法从数据库取到数据.错误提示:Sysyem.Net.WebException:远程服务器返回了错误:NotFound,监听发现请求数据库的服务异常,访问相 ...

  10. centos到底下载哪个版本?

    CentOS-7.0-1406-x86_64-DVD.iso             标准安装版,一般下载这个就可以了CentOS-7.0-1406-x86_64-NetInstall.iso    ...