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。唉,英文太差了!!加油!!

  • 相关阅读:
    线程中断总结
    线程的基本协作和生产者消费者
    synchronized总结
    线程基础总结
    Java集合总结(三):堆与优先级队列
    Java集合总结(二):Map和Set
    Java集合总结(一):列表和队列
    java枚举类型总结
    java 内部类简单总结
    java Integer包装类装箱的一个细节
  • 原文地址:https://www.cnblogs.com/xiaoxian1369/p/2694650.html
Copyright © 2011-2022 走看看