有谁的代码比我的短!!!
  • 板块P1167 刷题
  • 楼主qwe777
  • 当前回复14
  • 已保存回复14
  • 发布时间2025/2/1 11:03
  • 上次更新2025/2/4 10:32:13
查看原帖
有谁的代码比我的短!!!
1288382
qwe777楼主2025/2/1 11:03
#include<bits/stdc++.h>
using namespace std;
short Days[2][13]={{0,31,28,31,30,31,30,31,31,30,31,31,30},{0,31,29,31,30,31,30,31,31,30,31,31,30}};
int n,timein[5001],sy,ey,sm,em,sd,ed,sh,eh,ss,es,tail=1;
unsigned long long timeall,sum,at;
bool rn(int x){
    if(x%100==0){if(x%400==0)return 1;}
    else{if(x%4==0)return 1;}
    return 0;
}
bool comp(int x,int y){return x<y;}
int main(){
    cin>>n;for(int i=1;i<=n;i++)cin>>timein[i];sort(timein+1,timein+n+1,comp);
    scanf("%d-%d-%d-%d:%d",&sy,&sm,&sd,&sh,&ss);
    scanf("%d-%d-%d-%d:%d",&ey,&em,&ed,&eh,&es);
    timeall=eh*60+es-sh*60-ss;at+=timeall;
    for(int ny=sy;ny<=ey;ny++){
        bool rnm=rn(ny);
        for(int nm= ((ny==sy)?sm:1) ;nm<= ((ny==ey)?em:12) ;nm++){
            for(int nd = ((ny==sy && nm==sm)?sd:1);nd<= ((ny==ey && nm==em)?ed-1:Days[rnm][nm]) ;nd++)timeall+=1440;
            while(timein[tail]<=timeall && tail<=n){sum++;timeall-=timein[tail];tail++;}
        }
    }
    while(timein[tail]<=timeall && tail<=n){sum++;timeall-=timein[tail];tail++;}//可以不加,加上保险,而且由于tail的存在,不会浪费太长时间
    cout<<sum;
    return 0;
}

哼!

2025/2/1 11:03
加载中...