nyoj 605 Dice Tower

来源:互联网 发布:俄罗斯航空发动机知乎 编辑:程序博客网 时间:2024/06/05 01:56

Dice Tower

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
描述

A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).

                                

Alice and Bob play dice. Alice has built a tower from n dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).

Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.

输入
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of dice in the tower.

The second line contains an integer x (1 ≤ x ≤ 6) — the number Bob sees at the top of the tower. Next n lines contain two space-separated integers each: the i-th line contains numbers ai, bi (1 ≤ ai, bi ≤ 6; ai ≠ bi) — the numbers Bob sees on the two sidelong faces of the i-th dice in the tower.

Consider the dice in the tower indexed from top to bottom from 1 to n. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.
输出
Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).
样例输入
363 25 42 4
样例输出
YES
来源
Codeforces
上传者

李如兵

思路:就是其他的面能和顶面、顶面的对面相同

小编我一开始我就很天真的认为只要知道已知相邻两个面就能知道所有

但是题目会按常规给你正确的数据吗?他给你个顶面6 相邻面1 2你怎么判

想到这一点就可以秒懂了~

#include<stdio.h>int main(){    int t,n;    while(~scanf("%d%d",&t,&n))    {        int a,b;        int flag=1;        for(int i=0;i<t;i++)        {            scanf("%d%d",&a,&b);            if(a==n||a==7-n||b==n||b==7-n)                flag=0;        }        if(flag)            printf("YES\n");        else            printf("NO\n");    }    return 0;}


0 0
原创粉丝点击