我打赌没人想回答我的暴力代码,有第11点WA的数据

P2010 [NOIP2016 普及组] 回文日期

李夹木 @ 2021-08-13 10:05:31

直接给代码

#include <bits/stdc++.h>
using namespace std;
int a, b, t[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, sum;
bool hui(int x) {  //???????ж?
    int x1, s = 0;
    x1 = x;
    while (x1 > 0) {
        s = s * 10 + x1 % 10;
        x1 /= 10;
    }
    return s == x;
}
int z(int x) {
    int x1, s = 0;
    x1 = x;
    while (x1 > 0) {
        s = s * 10 + x1 % 10;
        x1 /= 10;
    }
    return s % 10000;
}
bool f(int x) {
    if (x % 100 == 0 || x % 400 != 0)
        return 0;
    if (x % 4 == 0)
        return 1;
    return 0;
}
int main() {
    //freopen("date.in", "r", stdin);
    //freopen("date.out", "w", stdout);
    cin >> a >> b;
    if (a / 10000 == b / 10000 && z(a) <= b % 10000) {
        cout << 1;
        return 0;
    }
    if (a == b && hui(a) == 1) {
        cout << 1;
        return 0;
    }
    if (a == b && hui(a) == 0) {
        cout << 0;
        return 0;
    }
    for (int i = a / 10000; i <= b / 10000; i++) {
        for (int j = 1; j <= 12; j++) {
            if (i == a / 10000 && j == a / 100 % 100) {
                if (j == 2 && f(i) == 1) {
                    for (int k = 1; k <= 29; k++) {
                        if (k >= a % 100 && hui(i * 10000 + j * 100 + k) == 1)
                            sum++;
                    }
                } else {
                    for (int k = 1; k <= t[k]; k++) {
                        if (k >= a % 100 && hui(i * 10000 + j * 100 + k) == 1)
                            sum++;
                    }
                }
            }
            if (i == b / 10000 && j == b / 100 % 10) {
                if (j == 2 && f(i) == 1) {
                    for (int k = 1; k <= 29; k++) {
                        if (k <= b % 100 && hui(i * 10000 + j * 100 + k) == 1)
                            sum++;
                    }
                } else {  //???????????
                    for (int k = 1; k <= t[k]; k++) {
                        if (k <= b % 100 && hui(i * 10000 + j * 100 + k) == 1)
                            sum++;
                    }
                }
            }
            if (i == a / 10000 && j != a / 100 % 100) {
                for (int k = 1; k <= t[j]; k++) {
                    if (j >= a / 100 % 100 && hui(i * 10000 + j * 100 + k) == 1)
                        sum++;
                }
            }
            if (i == b / 10000 && j != b / 100 % 100) {
                for (int k = 1; k <= t[j]; k++) {
                    if (j <= b / 100 % 100 && hui(i * 10000 + j * 100 + k) == 1)
                        sum++;
                }
            }
            if (i != a / 10000 && i != b / 10000) {
                if (j == 2 && f(i) == 1) {
                    for (int k = 1; k <= 29; k++) {
                        if (hui(i * 10000 + j * 100 + k) == 1)
                            sum++;
                    }
                } else {
                    for (int k = 1; k <= t[j]; k++) {
                        if (hui(i * 10000 + j * 100 + k) == 1)
                            sum++;
                    }
                }
            }
        }
    }
    if (a <= 92200229 && b >= 92200229)
        sum++;
    cout << sum;
    return 0;
}

数据:

输入: 20110101 20110105

输出: 0


by leoliuyixuan @ 2021-08-13 10:19:58

前排兜售大西瓜


by 李夹木 @ 2021-08-13 10:30:20

不回答我的问题的都不算!!!


by 清风雪月 @ 2021-08-15 20:24:23

@ljmhxs 这简单,加个特判


by 李夹木 @ 2021-08-17 09:24:52

@清风雪月 额,你认真的吗?

(其实也不是不可以)


by 清风雪月 @ 2021-08-17 18:37:32

@李夹木 考试的时候为了分数可以不择手段这没有违规,可以的


|