HDU 4982 Goffi and Squary Partition(推理)
HDU 4982 Goffi and Squary Partition
思路:直接从全然平方数往下找,然后推断是否能构造出该全然平方数,假设能够就是yes,假设都不行就是no。注意构造时候的推断,因为枚举一个全然平方数。剩下数字为kk。构造的时候要保证数字不反复
代码:
#include <cstdio>
#include <cstring>
#include <cmath> int n, k; bool judge(int num) {
int yu = num * num;
int kk = n - yu;
if (kk == 0) return false;
int sum = 0;
int cnt = 0;
for (int i = 0; i < k - 2; i++) {
cnt++;
if (cnt == kk) cnt++;
sum += cnt;
}
if (sum + kk >= n) return false;
int need = n - sum - kk;
if (need <= cnt) return false;
cnt++;
if (kk == cnt || kk == cnt + 1) {
if (need == kk) return false;
}
return true;
} bool solve() {
int m = sqrt(n * 1.0);
for (int i = m; i >= 1; i--) {
if (judge(i)) {
return true;
}
}
return false;
} int main() {
while (~scanf("%d%d", &n, &k)) {
if (solve()) printf("YES\n");
else printf("NO\n");
}
return 0;
}
HDU 4982 Goffi and Squary Partition(推理)的更多相关文章
- hdu 4982 Goffi and Squary Partition
Goffi and Squary Partition Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Subm ...
- 【HDOJ】4982 Goffi and Squary Partition
题意就是整数划分,选出和为n的K个整数,其中K-1个数的和为完全平方数S.选择整数时需要从1,2,3..连续选择,当选择整数与n-S相等时,需要跳过n-S,即选择n-S+1.如此选择K-2个数,从而可 ...
- hdu4982 Goffi and Squary Partition (DFS解法)
BestCoder Round #6 B http://acm.hdu.edu.cn/showproblem.php?pid=4982 Goffi and Squary Partition Time ...
- BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...
- Goffi and Squary Partition
题意: 给你N和K,问能否将N拆分成K个互不相同的正整数,并且其中K-1个数的和为完全平方数. PS:这道题目原来是要求输出一种可行方案的,所以下面题解是按照输出方案的思想搞的. 分析: 我们尝试枚举 ...
- HDU 4981 Goffi and Median(水)
HDU 4981 Goffi and Median 思路:排序就能够得到中间数.然后总和和中间数*n比較一下就可以 代码: #include <cstdio> #include <c ...
- hdu 4983 Goffi and GCD(数论)
题目链接:hdu 4983 Goffi and GCD 题目大意:求有多少对元组满足题目中的公式. 解题思路: n = 1或者k=2时:答案为1 k > 2时:答案为0(n≠1) k = 1时: ...
- HDU 4983 Goffi and GCD(数论)
HDU 4983 Goffi and GCD 思路:数论题.假设k为2和n为1.那么仅仅可能1种.其它的k > 2就是0种,那么事实上仅仅要考虑k = 1的情况了.k = 1的时候,枚举n的因子 ...
- hdu 4982 贪心构造序列
http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...
随机推荐
- maven Nexus 搭建本地中央仓库。
maven 网络中央仓库占用大量的网络资源,所以构建本地中央仓库. 过程如下: 下载地址: http://www.sonatype.org/nexus/archived 我用的是1.6的 [root@ ...
- Codeforces 475D CGCDSSQ 求序列中连续数字的GCD=K的对数
题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include < ...
- PAT 1055
题目链接:https://www.patest.cn/contests/pat-b-practise/1055 分析:思路很巧妙,感觉很有意义的字符串题目 #include<bits/stdc+ ...
- The usage of V$PGA_TARGET_ADVICE
Oracle 10g 给出了一系列的自动优化的建议,告诉我们PGA分配多大能给系统带来最大的性能?V$PGA_TARGET_ADVICE视图给出了很好的“预测”! 看一下这个视图能给我们带来什么样的信 ...
- JAVA线程相互排斥问题
public class TraditionalThreadSynchonized { public static void main(String[] args) { final OutPuter ...
- Delphi过程函数传递参数的八种方式
今天一同事问我为什么有些过程函数里面有Var而有些没有,不解,遂到网上百度,得解.快哉,快哉. 在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out.另一种不加修饰符的为默认按值传 ...
- leetcode解析回文子串拆分
转载请注明来自souldak,微博:@evagle Given a string s, partition s such that every substring of the partition i ...
- JavaScript 中创建对象的方法(读书笔记思维导图)
面向对象(Object-Oriented, OO)的语言有一个标志,那就是它们都有类的概念,而通过类可以创建任意多个具有相同属性和方法的对象.而 ECMAScript 中没有类的概念,所以我们可以使用 ...
- Struts2 后台action接收 jsp页面中checkbox中的值
如前端页面jsp中的标签为: <form action="myurl"> <input type="checkbox" name=" ...
- UVA 11080 - Place the Guards(二分图判定)
UVA 11080 - Place the Guards 题目链接 题意:一些城市.之间有道路相连,如今要安放警卫,警卫能看守到当前点周围的边,一条边仅仅能有一个警卫看守,问是否有方案,假设有最少放几 ...