80 pts 求助(带错误数据)

P1167 刷题

tmpliyijiang @ 2023-11-29 19:57:29

代码:

#include<bits/stdc++.h>
using namespace std;
int n,a[50050],t1[7],t2[7],tim1,tim2;
inline bool rn(int n){
    if(!(n%4)){
        if(!(n%100)){
            if(!(n%400))return 1;
            return 0;
        }
        return 1;
    }
    return 0;
}
int y[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
    scanf("%d",&n);
    for(register int i=0;i<n;i++){
        cin>>a[i];
    }
    char c;
    for(int i=0;i<5;i++){
        if(i!=4)cin>>t1[i]>>c;
        else{
            scanf("%d",&t1[i]);
        }
    }
    tim1+=t1[4];
    tim1+=t1[3]*60;
    tim1+=t1[2]*60*24;
    for(int i=0;i<t1[1];i++){
        tim1+=y[i]*24*60;
        if(i==1&&rn(t1[0]))tim1+=24*60;
    }
    for(register int i=0;i<t1[0];i++){
        if(rn(i))tim1+=24*60;
        tim1+=365*24*60;
    }
    for(int i=0;i<5;i++){
        if(i!=4)
        cin>>t2[i]>>c;
        else{
            scanf("%d",&t2[i]);
        }
    }
    tim2+=t2[4];
    tim2+=t2[3]*60;
    tim2+=t2[2]*60*24;
    for(int i=0;i<t2[1];i++){
        tim2+=y[i]*24*60;
        if(i==1&&rn(t2[0]))tim2+=24*60;
    }if(!n){
        cout<<0<<'\n';
        return 0;
    }
    for(register int i=0;i<t2[0];i++){
        if(rn(i))tim2+=24*60;
        tim2+=365*24*60;
    }
    //cout<<tim1<<endl<<tim2<<endl<<tim2-tim1<<endl;
    sort(a,a+n);
    /*for(register int i=0;i<n;i++){
        cout<<a[i]<<' ';
    }*/
    int cnt=0;
    for(register int i=0;i<n;i++){
        if(tim1+a[i]<=tim2){
            tim1+=a[i];
            cnt++;
            //cout<<"sum "<<i<<'='<<tim2-tim1<<'\n';
        }
    } 
    cout<<cnt<<endl;
    return 0;
}

错误数据:

100
7132
5111
638
7836
3809
1278
9578
7590
8245
5903
7611
4788
6810
1510
3564
3359
6412
996
4966
9801
5807
678
9175
9386
4146
1825
4869
9384
3639
2305
8130
1178
5102
2193
1739
1643
2965
7246
7051
2416
3779
5516
4395
3418
4869
9815
6073
5015
8501
210
3966
4891
8993
2883
5513
3775
799
9986
8190
4664
4361
241
7681
6235
7153
8032
8875
19
9254
1943
2049
8302
1848
9176
8699
6579
8112
4443
5158
8833
9849
6449
3882
2753
4101
1130
9517
4540
5516
9757
1047
3314
2938
576
8635
9440
8509
8
2596
3815
2007-02-05-00:00
2007-03-28-00:00

by tmpliyijiang @ 2023-11-29 19:58:36

数据正确输出:36

我的输出:37


by bcbgszyzh @ 2023-11-30 18:24:44

......

这么长的数据请问我这么回答?


by tmpliyijiang @ 2023-12-02 11:57:50

@bcbgszyzh 那么请读代码,谢谢,数据仅供参考。


by bcbgszyzh @ 2023-12-02 17:29:43

@tmpliyijiang ok 我看看


by ShelpAm @ 2024-01-04 19:20:21

同问,题主知道为什么错了吗?


by ShelpAm @ 2024-01-04 19:20:29

同问,题主知道为什么错了吗?


by Chenyufeng040525 @ 2024-03-18 01:19:07

@tmpliyijiang

月份那里错了,要多减个1,不然会分别多加28和31,相差多了3天,所以多做了一道题。


by tmpliyijiang @ 2024-03-18 19:23:50

@Chenyufeng040525 谢谢


|