来自萌新TLE的求助

P2010 [NOIP2016 普及组] 回文日期

EtOH_Lewis @ 2019-09-29 21:08:27

我脑子TLE了......

//why
#include<bits/stdc++.h>
using namespace std;
int ys,ms,ds,ye,me,de,s,e;
int rn[21]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int pn[21]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool runnian(int n)
{
        if(n%100!=0 && n%4==0)return true;
        if(n%100!=0 && n%4!=0)return false;
        if(n%400==0)return true;
        return false;
}
void dayturn()
{
        if(runnian(ys))
        {
                ds++;
                if(ds>rn[ms])ds=1,ms++;
                if(ms>12)ms=1,ys++;
        }
        if(!runnian(ys))
        {
                ds++;
                if(ds>pn[ms])ds=1,ms++;
                if(ms>12)ms=1,ys++;
        }
        s=ys*10000+ms*100+ds;
}
bool huiwen(int x)
{
        int i=x;
    int m=0;
    while(i>0)
    {
        m=m*10+i%10;
        i/=10;
    }
    return m==x?1:0;
}
int main()
{
        int counter=0;cin>>s>>e;
        ys=s/10000;ye=e/10000;
        ms=s/100%100;me=e/100%100;
        ds=s%100;de=e%100;
        dayturn();
        while(s!=e)
        {
                if(huiwen(s))counter++;
                dayturn();
        }
        cout<<counter<<endl;
}

by EtOH_Lewis @ 2019-09-29 21:10:47

//ys=year start ye=year end ms=month start......


by 辰星凌 @ 2019-09-29 21:25:33

先生您好,我们这里不提供模拟题的查错服务!


|