Case of Fake Numbers
来源:互联网 发布:linux sem trywait 编辑:程序博客网 时间:2024/05/16 01:01
Description
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages.
Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki integers — aij (1 ≤ aij ≤ m) — the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
Output
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
Sample Input
5 51 22 2 32 3 42 4 51 5
0
8 703 1 2 31 12 5 42 6 71 32 7 41 1
2
2 21 20
1
Hint
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2.
题目大意:一个序列有n个数,从1开始编号,每次对序列的操作是奇树为加一,偶数为减一,问经过有限次操作后能不能构成0,1,2,3,4·······n-1的序列。因为这个序列中的数都是在[0,n-1]区间内的数字,这个序列肯定经过n次数的操作之后会循环
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <cstdlib>#include <limits>#include <queue>#include <stack>using namespace std;#define N 1100#define INF 0xfffffff#define PI acos (-1.0)#define EPS 1e-8const int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};int main (){ int a[N], n; while (cin >> n) { int flag = 1; for (int i=0; i<n; i++) { cin >> a[i]; if ( i != a[i]) flag = 0; } for (int i=0; i<n && !flag; i++) { flag =1; for (int j=0; j<n; j++) { if (j % 2) a[j] = (a[j] + 1) % n; else a[j] = (a[j] + n - 1) % n; if (a[j] != j) flag = 0; } } if (flag) puts ("Yes"); else puts ("No"); } return 0;}
- Case of Fake Numbers
- B. Case of Fake Numbers
- CodeForces-556B Case of Fake Numbers
- codeforces 556B Case of Fake Numbers
- Codeforces 556B Case of Fake Numbers 数字转盘
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
- CF#310-B - Case of Fake Numbers-模拟水题
- 【66.47%】【codeforces 556B】Case of Fake Numbers
- B. Case of Fake Numbers( Codeforces Round #310 (Div. 2) 简单题)
- Fake Numbers
- Fake drag motion of Sprites
- the difference of real and fake fingerprint
- codeforces_C. Case of Matryoshkas
- A. Case of Matryoshkas
- case of 语句
- Case of Matryoshkas CodeForces
- 1506. Columns of Numbers
- A sequence of numbers
- 053第256题
- 有物品数量限制的背包问题
- 插入排序
- 记一次基于Unity的Profiler性能分析
- 某机构2006年培养学员8万人,每年增长25%,请问按此增长速度,到哪一年培训学员人数将达到20万人?
- Case of Fake Numbers
- UIView动画(过渡效果)的学习笔记
- 解决冲突(避免冲突)
- PowerPoint2007界面元素推荐
- [LeetCode][Java] Edit Distance
- 10285 - Longest Run on a Snowboard(DP)
- UNIX高级编程之简易版shell
- iOS9编程GOGOGO:XCode7新变化
- Unique Paths