题意:
给定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() ;
}
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() ;
}