10pts求调

P1167 刷题

zbf142103 @ 2024-08-14 20:34:39

#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename T> void read(T&x){
    int si=1;x=0;char c;
    do{c=getchar();if(c=='-') si=-1;}while(!isdigit(c));
    do{x=x*10+c-'0';c=getchar();}while(isdigit(c));
    x*=si;
}
const int N=5200;
int n,a[N],ans;
string b,e;
ll bf,ef,cf;
int cmo[13]={0,31,59,90,120,151,181,212,243,273,304,334,365};
bool pr(int y){
    if((y%400==0)||(y%100!=0&&y%4==0)) return 1;
    return 0;
}
void ds(){
    ll pa;
    ll y=b[0]*1000+b[1]*100+b[2]*10+b[3];
    y=y*365*24*60;
    ll m=b[5]*10+b[6];
    m=m*cmo[m]*24*60;
    ll d=b[8]*10+b[9];
    d=d*24*60;
    ll t=(b[11]*10+b[12])*60+b[14]*10+b[15];
    //-----------------------------------------------
    ll y1=e[0]*1000+e[1]*100+e[2]*10+e[3];
    y1=y1*365*24*60;
    ll m1=e[5]*10+e[6];
    m1=m1*cmo[m1]*24*60;
    ll d1=e[8]*10+e[9];
    d1=d1*24*60;
    ll t1=(e[11]*10+e[12])*60+e[14]*10+e[15];
    //---------------------------------------------
    pa=y+m+d+t;
    cf=y1+m1+d1+t1;
    if(pa>cf) swap(pa,cf);
    cf-=pa;
    if(y>y1) swap(y,y1);
    if(y1>y){
        for(int i=y;i<y1;++i){
            if(pr(i)) cf+=1*24*60;
        }
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    read(n);
    for(int i=1;i<=n;++i){
        read(a[i]);
    }
    cin>>b>>e;
    sort(a+1,a+n+1);
    for(int i=0;i<b.size();++i){
        b[i]-='0';
        e[i]-='0';
    }
    ds();
    for(int i=1;i<=n;++i){
        if(cf>=a[i]){
            cf-=a[i];
            ans++;
        }
        else break;
    }
    cout<<"\n"<<ans;
    return 0;
}

感谢


|