Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
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 fromNDice. 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.
Input
The first line contains a single integerN(1 digit ≤ DigitNLimit ≤0000100)
-The number of dice in the tower.
The second line contains an integerX(1 digit ≤ DigitXLimit ≤ limit 6 )-
The number Bob sees at the top of the tower. NextNLines contain two space-separated integers each:I-Th
Line contains numbersAI, Bytes,BI(1 digit ≤ DigitAI, Bytes,BILimit ≤ limit 6;AI =BI)-
The numbers Bob sees on the two sidelong faces ofI-Th dice in the tower.
Consider the dice in The Tower indexed from top to bottom from 1N. 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.
Output
Print "yes" (without the quotes), if it is possible to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible,
Print "no" (without the quotes ).
Sample test (s) Input
363 25 42 4
Output
YES
Input
332 64 15 3
Output
NO
Description: This question refers to the inference of the numbers on each side of the sieve by giving you these numbers. Because the numbers on the two sides of the question cannot be the same, and tells the top number. In order to extract all the planes, we must ensure that the number of the joint part of the horizontal plane is equal to the number on the top or relative to the number. Only in this way can we use the principle of matching the two faces. In this case, you only need to ensure that the number in the outer circle does not include the top number and its relative number.
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;int main(){int n,x,i;int flag;int a[101],b[101];flag=true;scanf("%d",&n);scanf("%d",&x);for(i=0;i<n;i++){scanf("%d %d",&a[i],&b[i]);if(a[i]==x||a[i]==7-x){flag=false;}if(b[i]==x||b[i]==7-x){flag=false;}}if(flag==true){printf("YES\n");}else{printf("NO\n");}return 0;}