题目描述:
在进行某些桌游,例如 UNO 或者麻将的时候,常常会需要随机决定从谁开始。骰子是一种好方案。普通的骰子有六个面,分别是一点、二点、三点、四点、五点、六点,六面向上的概率相同。由于骰子只能产生六种情况,而实际桌游时,却常常有三到四人,所以,我们在掷骰子时,常常采用两颗骰子,这个「随机的选择」就由骰子向上点数之和直接决定。
我们采用这么一种方案,将向上点数之和对 p (人数)取模,模出来的 0,1,…,p−1 恰好对应 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 ( 3≤p≤4 )。
第二行六个整数,用空格隔开,表示第一枚骰子的点数 a1,a2,a3,a4,a5,a6 ( 1≤ai≤6 )。
第三行六个整数,用空格隔开,表示第二枚骰子的点数 b1,b2,b3,b4,b5,b6 ( 1≤bi≤6 )。
Output
如果公平输出 YES
,否则输出 NO
。
Examples
4 1 2 3 4 5 6 1 2 3 4 5 6
NO
3 1 2 3 4 5 6 6 5 4 3 2 1
YES
解题思路:
一开始有好长段时间没读懂题意, 冒险交了一把果不其然WA, 然后冷静下来举了一下样例。 这道题其实就是看两个骰子的任两面和mod人数出来的数字是否对每个人都是公平的, 比如有三个人的时候是否mod出来的0, 1 ,2 个数是否是n0 == n1 == n2, 数据量小暴力直接过。
代码:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <cmath>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;
/*tools:
*ios::sync_with_stdio(false);
*freopen("input.txt", "r", stdin);
*/
typedef long long ll;
typedef unsigned long long ull;
const int dir[9][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1, 0, 0};
const ll ll_inf = 0x7fffffff;
const int inf = 0x3f3f3f;
const int mod = 1000000;
const int Max = (int) 2e4 + 7;
int n;
int a[10], b[10], num[10];
int main() {
//freopen("input.txt", "r", stdin);
int f = 0, temp = 0, cnt= 0;
scanf("%d", &n);
for (int i = 0; i < 6; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < 6; ++i) {
scanf("%d", &b[i]);
}
for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6 ; ++j) {
int temp = (a[i] + b[j]) % n;
num[temp]++;
}
}
if (n == 4) {
if (num[0] == num[1] && num[1] == num[2] && num[2] == num[3]) {
} else {
f = 1;
}
} else if (n == 3) {
if (num[0] == num[1] && num[1] == num[2]) {
} else {
f = 1;
}
}
if (!f) printf("YES\n");
else printf("NO\n");
return 0;
}