hdu 4859(思路题)
Goffi and Squary Partition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1171 Accepted Submission(s): 402
A set X 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 because 1 + 5 + 6 + 10 = 22 and 1 + 5 + 10 = 16 = 4 × 4.
Goffi wants to know, for some integers n and k, whether there exists a squary partition of n to k distinct positive integers.
4 2
22 4
YES
YES
/**
题意:给你k个数(各不相同的正整数),它们的和是n,问是否存在k-1个数的和是某个数的平方?
分析:我们假设其中k-1个数个数的平方为 m , m 应该不小于 k*(k-1)/2,不然就会有重复的 。
我们可以通过构造一个序列来判断是否满足条件。
*/
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
typedef long long LL; int n,k;
bool judge(int m){
int t = n-m, sum = (k-)*k/;
if(sum>m) return false; ///k-1项最小都要 sum
int count=,x=;
for(int i=;i<k-;i++){ ///构造出一个序列包含剩下的序列中的 k - 2 项
x++;
if(t==x) x++;
count+=x;
}
int lastnum = n-count-t; ///剩下的序列中的第 k-1 个数
if(lastnum<=x) return false; ///如果最后一个数小于 x ,那么之前肯定存在过了
x++;
if(t==x||t==x+){ ///如果 t == x 或者 t==x+1 那么当 第k-1个数等于t 的时候我们无法通过改变前k-2
///项的值令 lastnum != t 了,如果t更大一些,我们是可以通过改变 k-1这个序列的值
///来让 lastnum != t 的.
if(lastnum==t) return false;
}
return true;
}
int main()
{
while(scanf("%d%d",&n,&k)!=EOF){
bool flag = false;
for(int i=;i*i<n;i++){
int m = i*i;
if(judge(m)){
flag = true;
break;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}
hdu 4859(思路题)的更多相关文章
- hdu 4908(思路题)
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Proud Merchants HDU - 3466 (思路题--有排序的01背包)
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- hdu 5191(思路题)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 5101(思路题)
Select Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu 5063(思路题-反向操作数组)
Operation the Sequence Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4956(思路题)
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 5400(思路题)
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 1173 思路题
题目大意 有n个地点(坐标为实数)需要挖矿,让选择一个地点,使得在这个地方建造基地,到n个地点的距离和最短,输出基地的坐标. 题解+代码: 1 /* 2 把这个二维分开看(即把所有点投影到x轴上,再把 ...
- 51nod P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
随机推荐
- 25.VUE学习之-单击和双击事件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 数据结构-队列(Queue)
#include <stdio.h> #include <stdlib.h> #define LIST_INIT_SIZE 10 #define LISTINCREMENT 1 ...
- [BZOJ1010]玩具装箱toy(斜率优化)
Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...
- 2018年湘潭大学程序设计竞赛 E 吃货
题目描述 作为一个标准的吃货,mostshy又打算去联建商业街觅食了.混迹于商业街已久,mostshy已经知道了商业街的所有美食与其价格,而且他给每种美食都赋予了一个美味度,美味度越高表示他越喜爱这种 ...
- HDU 3368 Reversi
http://acm.hdu.edu.cn/showproblem.php?pid=3368 题意:模拟黑白棋,下一步黑手最大可以转化多少个白旗 分析:暴力 原先的思路是找到D然后遍历其八个方向,直到 ...
- Spring---环境搭建与包介绍
jar包下载路径 首先需要下载Spring框架 spring-framework-5.0.0.RELEASE-dist,官方地址为https://repo.spring.io/release/org/ ...
- MySQL基础3-SQL语言
1.DQL语句分类 重点在于Select语句 2.Sql语句的书写规则 3.怎样使用Navicat导入已经写好的sql文件 (1)在Navicat中右击选中的数据库 (2)将sql文件所在的路径添加进 ...
- IOS开发学习笔记042-UITableView总结2
一.自定义非等高的cell 如常见的微博界面,有的微博只有文字,有的有文字和图片.这些微博的高度不固定需要重新计算. 这里简单说一下几种方法.前面的步骤和设置等高的cell一样.现在来 ...
- noip 2018 d2t1 旅行
noip 2018 d2t1 旅行 (题目来自洛谷) 给定n个城市,m条双向道路的图, 不存在两条连接同一对城市的道路,也不存在一条连接一个城市和它本身的道路.并且, 从任意一个城市出发,通过这些道路 ...
- Normal synchronous FIFO mode 和 Show-ahead synchronous FIFO mode
FIFO是先进先出,可以用fifo来处理跨时钟域的数据传输问题,用到的地方特别多,一定要搞会. 在学习调用fifo的IP核中发现有normal synchronous FIFO mode 和 Show ...