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

  • 相关阅读:
    模块
    Queue(队列)
    Stack(栈)
    Vector(容器)
    位图像素的颜色
    大数处理之三(除法)
    大数处理之二(幂运算)
    浮点数(double)的优势
    大数处理之一(加法和乘法)
    Depth-First Search
  • 原文地址:https://www.cnblogs.com/xiaoxian1369/p/2694650.html
Copyright © 2011-2022 走看看