BestCoder Round #6(1002)hdu4982(贪心)
来源:互联网 发布:小学语文课文配音软件 编辑:程序博客网 时间:2024/06/14 08:31
Goffi and Squary Partition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18 Accepted Submission(s): 12
Problem Description
Recently, Goffi is interested in squary partition of integers.
A setX ofk distinct positive integers is called squary partition ofn if and only if it satisfies the following conditions:
- the sum of
k positive integers is equal ton - one of the subsets of
X containingk−1 numbers sums up to a square of integer.
For example, a set {1, 5, 6, 10} is a squary partition of 22 because 1 + 5 + 6 + 10 = 22 and 1 + 5 + 10 = 16 = 4 × 4.
Goffi wants to know, for some integersn andk , whether there exists a squary partition ofn tok distinct positive integers.
Input
Input contains multiple test cases (less than 10000). For each test case, there's one line containing two integersn andk (2≤n≤200000,2≤k≤30 ).
Output
For each case, if there exists a squary partition ofn tok distinct positive integers, output "YES" in a line. Otherwise, output "NO".
Sample Input
2 24 222 4
Sample Output
NOYESYES
题意:构造k个数,使得总和为n,且存在k-1个数的总和为一个完全平方数,能构造输出YES,否则输出NO
思路:贪心,先找到小于n且最接近n的完全平方数x,然后构造前k-1个数使得总和为x,那么第k个数固定为y=n-x
做到这里就可以分情况讨论了
1. y不等于1~k-1里的数,如果 y 不等于 k 则有解,如果 y=k ,如果x-k*(k-1)/2=1,则无解,否则有解
2. y等于1~k-1里的数,显然y不可能等于k了,则将1~k-1里等于y的数替换为k即可,只要前k-1个数的总和<=x则有解,否则无解
0 0
- BestCoder Round #6(1002)hdu4982(贪心)
- [BestCoder Round #4] hdu 4932 Miaomiao's Geometry (贪心)
- BestCoder Round #16 1002(hdu 5087)
- BestCoder Round #15(瞎搞)
- BestCoder Round #91(前两题)
- BestCoder Round #4 1002 Miaomiao's Geometry[贪心]
- BestCoder Round #79 1002/hdu 5661 Claris and XOR 贪心
- BestCoder Round #62 (div.2)Clarke and food (简单贪心)
- [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
- hdu4908 & BestCoder Round #3 BestCoder Sequence(组合数学)
- hdu 4990 Reading comprehension(BestCoder Round #8 1002)
- hdu5428(BestCoder Round #54 (div.2)1002题)
- BestCoder Round #56 1002 hdu 5464 (背包问题)
- BestCoder Round #70 1002 Jam's balance(DP)
- HDU 5666 Segment(BestCoder Round #80 1002)
- HDU 5671 Matrix (BestCoder Round #81 (div.2) 1002)
- BestCoder Round #74 (div.1) 1002Shortest Path(hdoj5636)
- BestCoder Round #92 1002 Count the Sheep(思维)【HDU6016】
- uva 11235 - Frequent values(RMQ)
- error_log()函数
- navigationBar tintColor barTintColor 分别在iOS7和它之前的区别
- Symmetric Tree
- 关于boost的shared_ptr以及weak_ptr的研究
- BestCoder Round #6(1002)hdu4982(贪心)
- hadoop之伪分布搭建
- 如何设置状态栏字体颜色
- UVA 10909 - Lucky Number(树状数组)
- JDBC笔记整理
- ASP编程十大技巧(基础)(转)
- 数组 不支持 引用
- 图书管理系统开发研究
- 自定义导航栏背景颜色