P2010 回文日期 题解

时间:2023-03-09 21:42:51
P2010 回文日期 题解

这题其实就是纯暴力,暴力,再暴力,毫无技巧可言(总之您怎么乱搞都不会超时QAQ)

首先,根据题意,我们明白每年自多产生一个回文日期,因为对于每年的三百多天,前四位是固定的。

所以,我们只需要进行一个从date1到date2之间的循环枚举,通过前四位找到后四位,再判断这八位数是否回文即可。

特别注意:

①:(其实题目里有讲)

一个年份是闰年当且仅当它满足下列两种情况其中的一种:

1.这个年份是4的整数倍,但不是100的整数倍;

2.这个年份是400的整数倍;

②:看到有些神犇的代码里对于“92200229”这个日期进行了特判,其实本蒟蒻感觉不需要,因为这个2月29日和9220年的条件不矛盾;

③:闰年2月有29日。

别问我这恶心的代码是怎么打出来的……

代码:

 #include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int s[],e[],sum;
bool run(int need)
{
if (need%==&&need%!=) return true;
else if (need%==) return true;
else return false;
}
int main()
{
for (int i=;i<=;i++) scanf("%1d",&s[i]);
for (int i=;i<=;i++) scanf("%1d",&e[i]);
#define __const__ s[1]*1000+s[2]*100+s[3]*10+s[4]
#define ___const___ e[1]*1000+e[2]*100+e[3]*10+e[4]
for (int i= __const__;i<=___const___;i++)
{
int cmp[]={,i/,i%/,i%/,i%,i%,i%/,i%/,i/};
if (!(cmp[]==cmp[]&&cmp[]==cmp[]&&cmp[]==cmp[]&&cmp[]==cmp[])) continue;
#define _const_ cmp[5]*10+cmp[6]
#define CONST cmp[7]*10+cmp[8]
if (_const_>||_const_<) continue;
if (CONST>||CONST<) continue;
if ((_const_==||_const_==||_const_==||_const_==||_const_==||_const_==||_const_==)&&CONST>) continue;
if ((_const_==||_const_==||_const_==||_const_==)&&(CONST>)) continue;
if ((_const_==&&CONST>&&run(cmp[]*+cmp[]*+cmp[]*+cmp[]))) continue;
if ((_const_==&&CONST>&&!run(cmp[]*+cmp[]*+cmp[]*+cmp[]))) continue;
if (i==___const___&&(_const_>e[]*+e[]||(_const_==e[]*+e[]&&CONST>e[]*+e[]))) continue;
if (i==__const__&&(_const_<s[]*+s[]||(_const_==s[]*+s[]&&CONST<s[]*+s[]))) continue;
sum++;
}
printf("%d\n",sum);
return ;
}