1 条题解

  • 0
    @ 2025-8-24 21:32:54

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar 「QQ红包」
    **

    搬运于2025-08-24 21:32:54,当前版本为作者最后更新于2016-12-02 22:52:05,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


    枚举后面四位(月份+日期)会更快。

    枚举后四位然后求出整个日期,判断是否在范围内即可。

    2月不需要判断是否是闰年,因为0229反过来是9220,整个日期是92200229,而9220年是闰年。

    #include<iostream> 
    #include<cstdio>
    #include<string>
    #include<map>
    #include<set>
    #include<queue>
    #include<vector> 
    using namespace std;
    int i,j,n,m,a,b,c,sum,ans;
    int s[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    int main()
    {
        scanf("%d%d",&n,&m);
        for (i=1;i<=12;i++)//枚举月和日 
            for (j=1;j<=s[i];j++)
            {
                c=(j%10)*1000+
                  (j/10)*100+
                  (i%10)*10+
                  (i/10);//算出前四位。
                sum=c*10000+i*100+j;//算出整个日期 
                if (sum<n||sum>m) continue;
                ans++;//统计 
            }
        printf("%d",ans);
        return 0;
    }
    
    • 1

    信息

    ID
    975
    时间
    1000ms
    内存
    128MiB
    难度
    2
    标签
    递交数
    2
    已通过
    1
    上传者