zoukankan      html  css  js  c++  java
  • codeforces #139 A dice tower

    题意:给你n个骰子,摆成一个塔,且相邻的骰子的接触的面的数字不同。而你看到的只有顶部和某两侧,现在给你的就顶部和某两侧的数字,请问,能否唯一判定所有面的数字。

    解法:既然要唯一,且顶部的数(假设为z)确定了,那么要不能唯一判定所有面的数字,那下面的某一个或几个骰子的侧面的数是z或7-z,如此,即可解题,代码如下:

    import java.io.BufferedInputStream;
    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner cin = new Scanner(new BufferedInputStream(System.in));
            int len = 101;
            int[] x = new int[len];
            int[] y = new int[len];
            int z = -1, n = -1;
            boolean flag;
            while (cin.hasNext()) {
                n = cin.nextInt();
                z = cin.nextInt();
                flag = true;
                for (int i = 0; i < n; i++) {
                    x[i] = cin.nextInt();
                    y[i] = cin.nextInt();
                    if (flag && (0 != i)) {
                        if (isTrue(x[i], z) || isTrue(y[i], z)) {
                            flag = false;
                        }
                    }
                }
                if (flag) {
                    System.out.printf("YES");
                } else {
                    System.out.printf("NO");
                }
            }
            cin.close();
        }
    
        private static boolean isTrue(int i, int z) {
            if (i == z || i + z == 7) {
                return true;
            }
            return false;
        }
    }


    昨天晚上理解错了,一直Wrong。唉,英文太差了!!加油!!

  • 相关阅读:
    全面解析Vue.nextTick实现原理
    js 宏任务和微任务
    模拟实现ES6的set类
    git客户端出现libpng warning: iCCP: known incorrect sRGB profile
    js封装、继承
    js单例模式
    并行运行多个python虚拟机
    关于场景服务的一些想法
    关于不能对闭包函数进行热更新的问题
    Python string interning原理
  • 原文地址:https://www.cnblogs.com/xiaoxian1369/p/2694650.html
Copyright © 2011-2022 走看看