我是靠谱客的博主 友好大船,最近开发中收集的这篇文章主要介绍codeforces 225 A,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

http://codeforces.com/problemset/problem/225/A

A. Dice Tower
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 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.

Input

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.

Output

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).

Sample test(s)
input
3
6
3 2
5 4
2 4
output
YES
input
3
3
2 6
4 1
5 3
output
NO
水题,关键在题意的理解。。。。

#include <string.h>
#include <stdio.h>
using namespace std;
int a[100002][3];
int main()
{
int n,x,m;
while(~scanf("%d",&n))
{
scanf("%d",&x);
for(int i=0;i<n;i++)
scanf("%d%d",&a[i][0],&a[i][1]);
int flag=1;
for(int i=0;i<n;i++)
{
m=x;
if(a[i][0]!=m&&a[i][0]!=7-m&&a[i][1]!=m&&a[i][1]!=7-m)
m=7-m;
else
{
flag=0;
break;
}
}
if(flag)
printf("YESn");
else
printf("NOn");
}
return 0;
}


最后

以上就是友好大船为你收集整理的codeforces 225 A的全部内容,希望文章能够帮你解决codeforces 225 A所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部