zoukankan      html  css  js  c++  java
  • SCUT

    https://scut.online/p/31
    还是不知道为什么RE了。的确非常玄学。
    重构之后就没问题了。果然写的越复杂,分的情况越乱就越容易找不到bug。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    int cnt[15];
    int cnt2[15];
    
    bool dfs(int x, int rest, bool dui) {
        if(rest == 0)
            return true;
        if(cnt2[x] == 0)
            return dfs(x + 1, rest, dui);
        if(cnt2[x] == 1) {
            if(x <= 7 && cnt2[x + 1] >= 1 && cnt2[x + 2] >= 1) {
                cnt2[x]--, cnt2[x + 1]--, cnt2[x + 2]--;
                if(dfs(x + 1, rest - 3, dui))
                    return true;
                cnt2[x + 2]++, cnt2[x + 1]++, cnt2[x]++;
            }
            return false;
        }
        if(cnt2[x] == 2) {
            if(!dui) {
                cnt2[x] -= 2;
                if(dfs(x + 1, rest - 2, true))
                    return true;
                cnt2[x] += 2;
            }
            if(x <= 7 && cnt2[x + 1] >= 2 && cnt2[x + 2] >= 2) {
                cnt2[x] -= 2, cnt2[x + 1] -= 2, cnt2[x + 2] -= 2;
                if(dfs(x + 1, rest - 6, dui))
                    return true;
                cnt2[x + 2] += 2, cnt2[x + 1] += 2, cnt2[x] += 2;
            }
            return false;
        }
        if(cnt2[x] >= 3) {
            if(!dui) {
                cnt2[x] -= 2;
                if(dfs(x, rest - 2, true))
                    return true;
                cnt2[x] += 2;
            }
            cnt2[x] -= 3;
            if(dfs(x, rest - 3, dui))
                return true;
            cnt2[x] += 3;
            if(x <= 7 && cnt2[x + 1] >= 1 && cnt2[x + 2] >= 1) {
                cnt2[x] --, cnt2[x + 1] --, cnt2[x + 2] --;
                if(dfs(x, rest - 3, dui))
                    return true;
                cnt2[x + 2] ++, cnt2[x + 1] ++, cnt2[x] ++;
            }
            return false;
        }
    }
    
    vector<int> ans;
    
    void check(int x) {
        memcpy(cnt2, cnt, sizeof(cnt2));
        cnt2[x]++;
        if(cnt2[x] > 4)
            return;
        int cnttwo = 7;
        for(int i = 1; i <= 9; ++i)
            cnttwo -= (cnt2[i] == 2);
        if(cnttwo == 0 || dfs(1, 14, false))
            ans.push_back(x);
    }
    
    int main() {
    #ifdef Yinku
        freopen("Yinku.in", "r", stdin);
    #endif // Yinku
        int T;
        char s[20];
        scanf("%d", &T);
        while(T--) {
            scanf("%s", s + 1);
            memset(cnt, 0, sizeof(cnt));
            for(int i = 1; i <= 13; ++i)
                cnt[s[i] - '0']++;
            ans.clear();
            for(int i = 1; i <= 9; ++i)
                check(i);
            if(ans.empty())
                ans.push_back(-1);
            for(auto i : ans)
                printf("%d", i);
            puts("");
        }
    }
    
  • 相关阅读:
    CodeForces 801C 二分,浮点数
    Cashier (codeforces 1059A)
    A + B Problem II (hdu1002)
    A water problem (hdu-5832)
    思维风暴 codeforces (1060A) Phone Numbers
    cin输入过慢用scanf???现在才知道cin可以加速
    uva 227 Puzzle (UVA
    uva 12108 Extraordinarily Tired Students (UVA
    uva340 Master-Mind Hints (UVA
    东抄西凑的凑出来了一个主题。。。代码高亮部分因为之前使用的都是另一个编译器导致没法高亮
  • 原文地址:https://www.cnblogs.com/Yinku/p/11308537.html
Copyright © 2011-2022 走看看