zoukankan      html  css  js  c++  java
  • java实现奇怪的比赛

    ** 奇怪的比赛**

    某电视台举办了低碳生活大奖赛。题目的计分规则相当奇怪:
    每位选手需要回答10个问题(其编号为1到10),越后面越有难度。答对的,当前分数翻倍;答错了则扣掉与题号相同的分数(选手必须回答问题,不回答按错误处理)。
    每位选手都有一个起步的分数为10分。
    某获胜选手最终得分刚好是100分,如果不让你看比赛过程,你能推断出他(她)哪个题目答对了,哪个题目答错了吗?
    如果把答对的记为1,答错的记为0,则10个题目的回答情况可以用仅含有1和0的串来表示。例如:0010110011 就是可能的情况。
    你的任务是算出所有可能情况。每个答案占一行。
    多个答案顺序不重要。

    答案写在“解答.txt”中,不要写在这里!

    参考答案:
    0010110011 (0分)
    0111010000 (4分)
    1011010000 (4分)

    import java.util.ArrayList;
    
    
    public class Main {
        public ArrayList<Integer> list = new ArrayList<Integer>();
        
        public void dfs(int[] A, int step) {
            while(step < A.length) {
                list.add(A[step]);
                check();
                step++;
                dfs(A, step);
                list.remove(list.size() - 1);
            }
            return;
        }
        
        public void check() {
            int[] value = new int[11];
            for(int i = 0;i < list.size();i++)
                value[list.get(i)] = 1;
            int x = 10;
            for(int i = 1;i < 11;i++) {
                if(value[i] == 0)
                    x = x - i;
                else if(value[i] == 1)
                    x = x * 2;
            }
            if(x == 100) {
                for(int i = 1;i < 11;i++)
                    System.out.print(value[i]);
                System.out.println();
            }
            return;
        }
        
        public static void main(String[] args) {
            Main test = new Main();
            int[] A = {1,2,3,4,5,6,7,8,9,10};
            test.dfs(A, 0);
        }
    }
    
  • 相关阅读:
    Entity Framework 连接低版本数据库
    Validate Disk Failover Failed
    Unable to create Azure Mobile Service: Error 500
    查看Visual Studio异常内容
    RDLC An unexpected error occurred while compiling expressions. Native compiler return value: '-1073741511'
    Redis 64 steps
    IQueryable join 的问题
    jquery 通知页面变化
    jquery 让滚动条处于div底部
    SSIS 文件系统任务无法使用变量配置目标路径
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12947338.html
Copyright © 2011-2022 走看看