B4191 题解

· · 题解

题目传送门

思路

可以以分钟为单位进行枚举

枚举起点为 T=(h\times60+m+1)\bmod D,每一次向后增加 1 分钟 T\gets(T+1)\bmod D。其中 D 为常数,值为 D=24\times60,代表一天的分钟数量。判断回文时再将 T 拆开,令 X=\lfloor\frac{T}{60}\rfloorY=T\bmod60,即为当前的点数。如果满足 \lfloor\frac{X}{10}\rfloor=Y\bmod10X\bmod10=\lfloor\frac{Y}{10}\rfloor,则日期 \texttt{X:Y} 回文,输出即可。

AC CODE

#include<bits/stdc++.h>
using namespace std;
int read(){int x=0;char f=1,ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return x*f;}
const int D=24*60;
int main(){
    int a=read(),b=read();
    for(int t=(a*60+b+1)%D;;t=(t+1)%D){
        int x=t/60,y=t%60;
        if(x/10==y%10&&x%10==y/10)
            return printf("%02d:%02d\n",x,y),0;
    }
    return 0;
}