【CUGBACM15级BC第六场 B】hdu 4982 Goffi and Squary Partition
来源:互联网 发布:剑三藏剑叶英脸型数据 编辑:程序博客网 时间:2024/05/22 16:49
Goffi and Squary Partition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1588 Accepted Submission(s): 527
Total Submission(s): 1588 Accepted Submission(s): 527
Problem Description
Recently, Goffi is interested in squary partition of integers.
A setX of k distinct positive integers is called squary partition of n if and only if it satisfies the following conditions:
[ol]
the sum of k positive integers is equal to n
one of the subsets of X containing k−1 numbers sums up to a square of integer.[/ol]
For example, a set {1, 5, 6, 10} is a squary partition of 22 because1 + 5 + 6 + 10 = 22 and 1 + 5 + 10 = 16 = 4 × 4.
Goffi wants to know, for some integersn and k , whether there exists a squary partition of n to k distinct positive integers.
A set
[ol]
For example, a set {1, 5, 6, 10} is a squary partition of 22 because1 + 5 + 6 + 10 = 22 and 1 + 5 + 10 = 16 = 4 × 4.
Goffi wants to know, for some integers
Input
Input contains multiple test cases (less than 10000). For each test case, there's one line containing two integersn and k (2≤n≤200000,2≤k≤30 ).
Output
For each case, if there exists a squary partition ofn to k distinct positive integers, output "YES" in a line. Otherwise, output "NO".
Sample Input
2 24 222 4
Sample Output
NOYESYES
题目大意:给出n,k。问是否存在一个k个数字的序列,和为n,并且其中存在k-1个数字的和是一个完全平方数。
例如:{1, 5, 6, 10}, n为22,k为 3的时候, 1 + 5 + 6 + 10 = 22 and 1 + 5 + 10 = 16 = 4 × 4.所以符合#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int main(){ int n, k; while (scanf("%d%d", &n, &k) != EOF) { int flag = 0; int sum = k * (k - 1) / 2; for (int i = 1; i * i < n; i++) { int squre = i * i; int need = n - squre; if (squre < sum) { continue; } if (need <= k - 1 && sum + k > n) { continue; } if (squre == sum + 1 && need == k) { continue; } flag = 1; break; } if (flag) { printf("YES\n"); } else { printf("NO\n"); } } return 0;}
阅读全文
0 0
- 【CUGBACM15级BC第六场 B】hdu 4982 Goffi and Squary Partition
- bc第六场Goffi and Squary Partition
- Goffi and Squary Partition-HDU-4982 BC.6.B
- HDU 4982/BC 6B Goffi and Squary Partition
- 【CUGBACM15级BC第六场 A】hdu 4981 Goffi and Median
- hdu 4982 Goffi and Squary Partition(构造)
- hdu 4982 Goffi and Squary Partition
- hdu 4982 Goffi and Squary Partition (枚举)
- HDU 4982 Goffi and Squary Partition
- HDU 4982 Goffi and Squary Partition(推理)
- hdu 4982 Goffi and Squary Partition(BestCoder Round #6)
- hdu 4982 Goffi and Squary Partition (想法题)
- HDU 4982 Goffi and Squary Partition(枚举)
- HDU-4982-Goffi and Squary Partition【贪心】【构造】
- hdu 4982 Goffi and Squary Partition(思路)
- 【杂题】 HDOJ 4982 Goffi and Squary Partition
- HDOJ 4982 Goffi and Squary Partition
- HDU4982 Goffi and Squary Partition
- 数据挖掘笔试题
- ubuntu16.04 下 使用update-alternatives 更换python 版本
- VS2010中GetMenu()和GetSubMenu(0)为NULL引发异常(2)
- linux Boot目录满了之后的解决方法
- sed参数是变量,变量中有特殊字符,如何处理
- 【CUGBACM15级BC第六场 B】hdu 4982 Goffi and Squary Partition
- Matlab中的sum函数以及sum(,3)求和函数
- win10环境git bash使用
- ES6 —(async 函数)
- 颜色空间转换
- 注解
- MusicPlayer下build.gradle的依赖
- oracle数据库习题1
- Linux C常用头文件及函数