[蓝桥杯] 带分数

[蓝桥杯] 带分数

峰值内存消耗 < 64M  CPU消耗  < 3000ms

【题目描述 - Problem Description】

    100 可以表示为带分数的形式:100 = 3 + 69258 / 714

    还可以表示为:100 = 82 + 3546 / 197

    注意特征:带分数中,数字1~9分别出现且只出现一次(不包含0)。

    类似这样的带分数,100 有 11 种表示法。

【输入样例 1 - Sample Input 1】

【输出样例 1 - Sample Output 1】

100 11

【输入样例 2 - Sample Input 2】

【输出样例 2 - Sample Output 2】

105 6

 【题解】

大概估计了一下打表的极限计算量,1s应该勉勉强强可以碰碰运气,然后回头看了看时间给了3s……

大脑立刻终止了其他解法的思考……

【代码 C++】

#include<cstdio>
#include<algorithm>
#define mx 1000005
int data[9], opt[mx];
int read(int L, int R){//[L, R]
    int s = 0;
    for (; L <= R; ++L){
        s = s * 10 + data[L];
    }
    return s;
}
int main(){
    int i, al, ar, bl, br, a, b, c;
    for (i = 0; i < 9; ++i) data[i] = i + 1;
    do{
        for (al = ar = 0; ar <= 6; ++ar){
            a = read(al, ar);
            for (bl = br = ar + 1; br - bl + 1 < 8 - bl; ++br){
                b = read(bl, br), c = read(br + 1, 8);
                if (c / b*b != c) continue;
                if (a + c / b < mx) ++opt[a + c / b];
            }
        }
    } while (std::next_permutation(data, data + 9));
    scanf("%d", &i);
    printf("%d", opt[i]);
    return 0;
}

【可测评地址】http://acmore.cc/problem.php?id=1596

posted @ 2016-03-21 17:09  Simon_X  阅读(438)  评论(0编辑  收藏  举报