离谱的02优化

P2010 [NOIP2016 普及组] 回文日期

yinqf @ 2022-10-11 08:41:58

82分代码:

#include<bits/stdc++.h>
using namespace std;
int a,b,ans;
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int huiwen(int x){
    int xh=0,xz=0,t=0;
    xz=x;
    while(t<=7){
        xh=xh*10+x%10;
        x=x/10;
        t++;
    }
    if(xh==xz){
        return 1;
    }
    return 0;
}
int possible(int x){
    int year,mouth,day;
    year=x/10000;
    mouth=x%10000/100;
    day=x%100;
    if((year%4==0&&year%100!=0||year%400==0)&&mouth==2){//这个年份是4的整数倍,不是100的整数倍,是400的整数倍;
        if(day<=29){
            return 1;
        }
        else{
            return 0;
        }
    }
    else{
        if(mouth<=12){
            if(day<=m[mouth]){
                return 1;
            }
            else{
                return 0;
            }
        }
        else{
            return 0;
        }
    }

}
int main(){
    cin >> a >> b;
    for(int i=a;i<=b;i++){
        if(huiwen(i)&&possible(i)){
            ans++;
        }
    }
    cout << ans;
    return 0;
}

开02就AC了!!!

离谱!!!


by _lmh_ @ 2022-10-11 08:47:46

知道了,下一个


by FiraCode @ 2022-10-11 08:50:09

@yinlg O2不就是优化时间的吗


by yinqf @ 2022-10-11 08:51:07

@FiraCod 好像优化了时间,因为是TLE


by AC_CSP @ 2022-10-11 08:54:31

@yinlg \text{swdywtmbwtp}


by 向晚大魔王 @ 2022-10-11 09:04:55

02/口水黄豆


by Steven_lzx @ 2022-10-11 09:06:06

所以你想要表达什么。。。


by HeCao2008 @ 2022-10-11 09:11:32

知道了


by LuoTianyi_Official @ 2022-10-11 09:35:14

02


|