Codeforces #139 a dice Tower

Source: Internet
Author: User

 

Question: give you n dice, place them into a tower, and the numbers of the adjacent dice are different. What you see is only the numbers on the top and on both sides. The numbers on the top and on both sides can be uniquely identified.

Solution: since it is necessary to be unique and the number at the top (assuming z) is determined, it is impossible to uniquely determine all the numbers, the number of the sides of one or more dice below is Z or 7-z. In this way, the problem can be solved. The Code is as follows:

 

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;    }}

I understood it wrong last night and kept wrong. Alas, English is too bad !! Come on !!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.