为什么只有60分???

P1167 刷题

lmrttx @ 2021-02-14 14:36:22

RT,代码如下,long long 开了。

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,t[5001],ans,tot;
int y11,m1,d1,h1,min1;
int y2,m2,d2,h2,min2;
int mon1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int mon2[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool check(int year){
    if(year%4==0){
        if(year%100==0){if(year%400==0)return 1;else return 0;}
        else return 1;
    }else return 0;
}
void work1(){ 
    for(int i=y11;i<y2;i++)if(check(i)){
        tot+=366;
    }else tot+=355;
    return;
}
void work2(){
    for(int i=1;i<m1;i++)if(check(y11))tot-=mon2[i];
    else tot-=mon1[i];
    for(int i=1;i<m2;i++)if(check(y2))tot+=mon2[i];
    else tot+=mon1[i];return;
}
void work3(){
    tot=(tot-d1+d2)*24*60;
    tot=tot-(60*h1+min1)+(60*h2+min2);
    return;
}
signed main(){
    scanf("%lld",&n);for(int i=1;i<=n;i++){
        scanf("%d",&t[i]);
    }
    sort(t+1,t+n+1);
    scanf("%lld-%lld-%lld-%lld:%lld",&y11,&m1,&d1,&h1,&min1);
    scanf("%lld-%lld-%lld-%lld:%lld",&y2,&m2,&d2,&h2,&min2);
    work1();work2();work3();
    for(int i=1;i<=n;i++){
        if(tot>=t[i])tot-=t[i],ans++;
        else break;
    }
    printf("%lld",ans);return 0;
}

谢谢!


by kebingyi @ 2021-02-14 15:50:48

@lmrttx 或许是因为 mon1 与 mon2 里的值是一样的导致的?


by lmrttx @ 2021-02-14 15:51:27

@kebingyi 谢谢!忘记把28改29了。。。谢谢哈


by kebingyi @ 2021-02-14 16:18:26

@lmrttx 可以再考虑一下第一年和最后一年是闰年,2 月份是否要算进去的情况。(看你好像还没过


by kebingyi @ 2021-02-14 17:05:23

@lmrttx

work 后加上这个试试:

if(check(y1)&&m1>2)t--;
if(check(y2)&&m2>2)t++;

by lmrttx @ 2021-02-15 10:33:19

@kebingyi 还是60,笑哭


|