zoukankan      html  css  js  c++  java
  • USACO 1.2.1 Milking Cows

    题意:

            给定N个挤奶工取奶的起始时间和结束时间,求其中至少一个在取奶的最长时间和都没在取奶的最长时间。起止时间为5:00后以秒为单位的时间点,一个挤奶工对应一头奶牛。

            又一道让BUG给挂掉的题,这次还更无语。

    input

    4
    100 200
    201 301
    302 402
    403 503

    output

    100 1

            我运行的确实是"100 1"啊,可那测评系统非说我运行的是"100 0",无奈...

      > Run 2: Execution error: Your program did not produce an answer
            that was judged as correct. The program stopped at 0.000 seconds;
            it used 3064 KB of memory. 
    
            Here are the respective outputs:
            ----- our output ---------
            100_1
            ---- your output ---------
            100_0
            --------------------------
    
            ------ Data for Run 2 ------
            4 
            100 200 
            201 301 
            302 402 
            403 503 
            ----------------------------

    /*
    ID: sdaujsj1
    LANG: C++
    TASK: milk2
    */
    #include 
    <iostream>
    #include
    <stdlib.h>
    #include
    <fstream>
    using namespace std ;
    int i, j, n ;
    struct row{
        
    int begin, end ;
    }a[
    5010] ;
    int cmp(const void *a, const void *b){
        
    return (*(row *)a).begin > (*(row *)a).begin ? -1 : 1 ;
    }
    int find(int x){
        
    int k = -1, max = a[x].end ;
        
    for(i=x+1; i<n; i++){
            
    if(a[i].begin<=a[x].end){
                
    if(a[i].end>max){
                    max 
    = a[i].end ;
                    k 
    = i ;
                }
            }
        }
        
    return k ;
    }
    int find1(int x){
        
    int k ;
        
    for(k=x+1; k<n; k++)
            
    if(a[k].begin>a[x].end)    break ;
        
    return k ;
    }
    int main(){
        ifstream fin (
    "milk2.in");
        fin 
    >> n ;
        
    for(i=0; i<n; i++)
            fin 
    >> a[i].begin >> a[i].end ;
        qsort(a, n, 
    sizeof(a[0]), cmp) ;
        fin.close();
        j 
    = 0 ;
        
    int sum = a[0].end - a[0].begin ;
        
    int bsum = 0 ;
        
    int mbegin = a[0].begin ;
        
    while(true){
            
    int temp = j ;
            j 
    = find(j) ;
            
    if(j!=-1){
                
    if(a[j].end - mbegin>sum)  sum = a[j].end - mbegin ;
            }
            
    else{
                j 
    = find1(temp) ;
                
    if(j!=n){
                    mbegin 
    = a[j].begin ;
                    
    if(a[j].begin - a[temp].end>bsum)  bsum = a[j].begin - a[temp].end ;
                }
                
    else    break ;
            }
        }
        ofstream fout (
    "milk2.out") ;
        fout 
    << sum << " " << bsum << endl ;
        fout.close() ;
    }
  • 相关阅读:
    泛型约束 where T : class,new()
    在Navicat for MySQL中打开视图时,提示视图没有主键的问题
    转:JQuery实现下拉框的数据加载和联动
    查询每门课程最高分的学生的学号,课程号,成绩
    转:SQL子句的执行顺序
    端口映射
    服务器与个人电脑的区别
    花生壳使用指南
    如何测试本机的公网IP能否被Internet用户访问
    利用ADSL拨号上网方式如何搭建服务器
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2154704.html
Copyright © 2011-2022 走看看