LightOJ - 1356
2017-07-04 09:12
204 查看
素数+二分图
二分图我不会暂时就不给代码了
A set of integers is called prime independent if none of its member is a prime multiple of another member. An integer
a is said to be a prime multiple of b if,
a = b x k (where k is a prime [1])
So, 6 is a prime multiple of 2, but
8 is not. And for example, {2, 8, 17} is prime independent but
{2, 8, 16} or {3, 6} are not.
Now, given a set of distinct positive integers, calculate the largest prime independent subset.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with an integer N (1 ≤ N ≤ 40000) denoting the size of the set. Next line contains
N integers separated by a single space. Each of these N integers are distinct and between
1 and 500000 inclusive.
Output
For each case, print the case number and the size of the largest prime independent subset.
Sample Input
3
5
2 4 8 16 32
5
2 3 4 6 9
3
1 2 3
Sample Output
Case 1: 3
Case 2: 3
Case 3: 2
题意:给你一串数,求他们最大的质数独立集的长度,质数独立集是一个集合中的所有数两两之间不能通过乘一个素数得到
思路:大概就是建一个二分图来解,二分图需要以两个数之间是否可以通过乘一个素数得到来判断加不加边,关于判断的方法:
给一个数分解质因子,然后分别除以每一个质因子,看得到的那个数[b]是否存在在给的数列中,存在的话这两个数就prime multiple(因为a[i]<=500000,可以存下每一个数是否存在,并且质因子也不多)[/b]
然后就是根据质因子数目是奇数还是偶数分成两边,然后根据[b]prime multiple关系连边,然后二分图匹配[/b]
不过要注意的是此题时间卡的紧
大概就是这样了
(本人菜的抠脚暂时不会二分图,所以只能这样了)
二分图我不会暂时就不给代码了
A set of integers is called prime independent if none of its member is a prime multiple of another member. An integer
a is said to be a prime multiple of b if,
a = b x k (where k is a prime [1])
So, 6 is a prime multiple of 2, but
8 is not. And for example, {2, 8, 17} is prime independent but
{2, 8, 16} or {3, 6} are not.
Now, given a set of distinct positive integers, calculate the largest prime independent subset.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with an integer N (1 ≤ N ≤ 40000) denoting the size of the set. Next line contains
N integers separated by a single space. Each of these N integers are distinct and between
1 and 500000 inclusive.
Output
For each case, print the case number and the size of the largest prime independent subset.
Sample Input
3
5
2 4 8 16 32
5
2 3 4 6 9
3
1 2 3
Sample Output
Case 1: 3
Case 2: 3
Case 3: 2
题意:给你一串数,求他们最大的质数独立集的长度,质数独立集是一个集合中的所有数两两之间不能通过乘一个素数得到
思路:大概就是建一个二分图来解,二分图需要以两个数之间是否可以通过乘一个素数得到来判断加不加边,关于判断的方法:
给一个数分解质因子,然后分别除以每一个质因子,看得到的那个数[b]是否存在在给的数列中,存在的话这两个数就prime multiple(因为a[i]<=500000,可以存下每一个数是否存在,并且质因子也不多)[/b]
然后就是根据质因子数目是奇数还是偶数分成两边,然后根据[b]prime multiple关系连边,然后二分图匹配[/b]
不过要注意的是此题时间卡的紧
大概就是这样了
(本人菜的抠脚暂时不会二分图,所以只能这样了)
相关文章推荐
- LightOJ 1356 Prime Independence (素数+二分图)
- LightOJ 1356 Prime Independence( Hopcroft–Karp Bipartite算法)
- LightOJ 1356 Prime Independence(素数筛选法+最大独立集)(Hopcroft-Carp算法)
- LightOJ 1356 Aladdin and the Flying Carpet(唯一分解定理)
- Lightoj-1356 Prime Independence(质因子分解)(Hopcroft-Karp优化的最大匹配)
- LightOJ 1356 Prime Independence
- lightoj 1356 - Prime Independence 【质因子分解 奇偶构图 + HK优化】
- Lightoj-1356 Prime Independence(质因子分解&&二分图最大独立集)
- LightOJ 1356 && LightOJ 1336
- LightOJ 1356 Prime Independence 二分图最大独立集,HK算法
- LightOj1356-Prime Independence
- LightOJ - 1356 质因数分解+最大独立子集
- LightOJ-1356 Prime Independence
- Lightoj-1356 Prime Independence(质因子分解)(Hopcroft-Karp优化的最大匹配)
- LightOJ 1356 Prime Independence (素数 二分图)
- 基础数学 1002 LightOJ 1356
- LightOJ-1356-二分图匹配Hopcroft-Carp+数论
- LightOJ 1356 Prime Independence(质因数分解+最大独立集+Hopcroft-Carp)
- LightOJ 1031 区间dp
- lightoj 1296 - Again Stone Game 博弈论