A唐纳德先生和假骰子(华师网络赛)

Time limit per test: 1.0 seconds

Memory limit: 256 megabytes

在进行某些桌游,例如 UNO 或者麻将的时候,常常会需要随机决定从谁开始。骰子是一种好方案。普通的骰子有六个面,分别是一点、二点、三点、四点、五点、六点,六面向上的概率相同。由于骰子只能产生六种情况,而实际桌游时,却常常有三到四人,所以,我们在掷骰子时,常常采用两颗骰子,这个「随机的选择」就由骰子向上点数之和直接决定。

我们采用这么一种方案,将向上点数之和对 p(人数)取模,模出来的 0,1,,p1 恰好对应 p 个人。但这并不一定是公平的。例如,如果你有算过的话,两枚普通的骰子,在四个人的情形下,就是不公平的。

所以唐纳德先生发明了一种假骰子,这种假骰子也有六个面,但六个面的点数就不再是 1,2,3,4,5,6,而是 a1,a2,a3,a4,a5,a6。如果他精心选择了这六个面的点数,他仍然可以强制公平。

先给出 p 和两枚假骰子六个面的点数,问是否公平。

Input

输入具有如下形式:

pa1 a2 a3 a4 a5 a6b1 b2 b3 b4 b5 b6

第一行一个整数 p (3p4)。

第二行六个整数,用空格隔开,表示第一枚骰子的点数 a1,a2,a3,a4,a5,a6 (1ai6)。

第三行六个整数,用空格隔开,表示第二枚骰子的点数 b1,b2,b3,b4,b5,b6 (1bi6)。

Output

如果公平输出 YES,否则输出 NO

Examples

input

4
1 2 3 4 5 6
1 2 3 4 5 6

output

NO

input

3
1 2 3 4 5 6
6 5 4 3 2 1

output

YES

签到题,我读题慢,没读完LZh已经开始写了。。。所以现在才看题。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}
int a[10],b[10];
int P;
int tim[10];
int main(){
    P=read();
    for(int i=1;i<=6;i++)
        a[i]=read();
    for(int j=1;j<=6;j++)
        b[j]=read();
    for(int i=1;i<=6;i++)
        for(int j=1;j<=6;j++)
            tim[(a[i]+b[j])%P]++;
    if(36%P!=0){
        printf("NO
");
        return 0;
    }
    for(int i=0;i<P;i++)
        if(tim[i]!=36/P){
            printf("NO
");
            return 0;
        }
    printf("YES
");
    return 0;
}
原文地址:https://www.cnblogs.com/hua-dong/p/8011205.html