20WA求助

P1167 刷题

lihaokai_juruo @ 2024-12-01 19:50:17

本人排序+贪心搞定

计算时间有问题 (因为本人瞎写)

代码:

#include<bits/stdc++.h>
using namespace std;
int a[6000];
int mp[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int mr[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int isrun(int y)
{
    if(y%4==0&&y%100!=0)return 1;
    else if(y%400==0)return 1;
    else return 0;
}
int main()
{
    int n;
    unsigned long long time=0;
    int ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    int y1,m1,d1,h1,M1;
    int y2,m2,d2,h2,M2;
    char c;
    cin>>y1>>c>>m1>>c>>d1>>c>>h1>>c>>M1;
    cin>>y2>>c>>m2>>c>>d2>>c>>h2>>c>>M2;
    for(int i=y1;i<=y2;i++)
    {
        if(isrun(i)==1)time+=366*24*60;
        else time+=365*24*60;
    }
    for(int i=m1;i<=m2;i++)
    {
        if(isrun(i)==1)time+=mr[i]*24*60;
        else time+=mp[i]*24*60;
    }
    for(int i=d1;i<=d2;i++)
    {
        time+=24*60;
    }
    for(int i=h1;i<=h2;i++)
    {
        time+=60;
    }
    for(int i=M1;i<=M2;i++)
    {
        time++;
    }
    sort(a+1,a+n+1);
    int i=1;
    while(time>=a[i]&&i<=n)
    {
        time-=a[i];
        ans++;
        i++;
    }
    cout<<ans;
    return 0;
}

求助,玄关


|