zoukankan      html  css  js  c++  java
  • [蓝桥杯] 带分数

    [蓝桥杯] 带分数

    峰值内存消耗 < 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

  • 相关阅读:
    [杂说]网络是基础生产工具
    这几天的工作
    [代码]大家来动动脑筋吧
    测试
    [基础] 如何使用extern和static限定符
    元宵节快乐
    复杂的“人"
    C# SMTP发邮件不支持465端口的解决方案,网易企业邮箱
    软件三层架构模型
    ASP.NET MVC 使用二级域名来注册Area区域
  • 原文地址:https://www.cnblogs.com/Simon-X/p/5302735.html
Copyright © 2011-2022 走看看