题意就是整数划分,选出和为n的K个整数,其中K-1个数的和为完全平方数S。
选择整数时需要从1,2,3..连续选择,当选择整数与n-S相等时,需要跳过n-S,即选择n-S+1。
如此选择K-2个数,从而可确定第K-1个数,若该数已经出现(小于或等于K-2),则划分失败;
若第K-1个数不等于n-S,则肯定划分成功,否则K-1个数若等于n-S。
即需要通过将第K-2个数+1,同时第K-1个数-1得到正确的划分,并且需要保证调整后第K-2个数仍小于第K-1个数,因此,两数之间的距离至少大于2。

 #include <cstdio>
#include <cmath> int n, k; bool judge(int s) {
int p, q;
int i, j = , sum = , tmp; p = s*s;
if (n == p)
return false;
q = n-p; for (i=; i<=k-; ++i) {
++j;
if (j == q)
++j;
sum += j;
}
if (sum >= p)
return false;
tmp = p - sum;
if (tmp <= j)
return false;
if (tmp == q) {
if (q <= j+)
return false;
}
return true;
} int main() {
int m; while (scanf("%d %d", &n, &k) != EOF) {
m = sqrt((n-)*1.0); if (judge(m))
printf("YES\n");
else
printf("NO\n");
} return ;
}

【HDOJ】4982 Goffi and Squary Partition的更多相关文章

  1. HDU 4982 Goffi and Squary Partition(推理)

    HDU 4982 Goffi and Squary Partition 思路:直接从全然平方数往下找,然后推断是否能构造出该全然平方数,假设能够就是yes,假设都不行就是no.注意构造时候的推断,因为 ...

  2. hdu 4982 Goffi and Squary Partition

    Goffi and Squary Partition Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Subm ...

  3. 【HDOJ】4983 Goffi and GCD

    题意说的非常清楚,即求满足gcd(n-a, n)*gcd(n-b, n) = n^k的(a, b)的不同对数.显然gcd(n-a, n)<=n, gcd(n-b, n)<=n.因此当n不为 ...

  4. hdu4982 Goffi and Squary Partition (DFS解法)

    BestCoder Round #6 B http://acm.hdu.edu.cn/showproblem.php?pid=4982 Goffi and Squary Partition Time ...

  5. 【LeetCode】数组-6(561)-Array Partition I(比较抽象的题目)

    题目描述:两句话发人深思啊.... Given an array of 2n integers, your task is to group these integers into n pairs o ...

  6. BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...

  7. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  8. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  9. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

随机推荐

  1. 山东省赛J题:Contest Print Server

    Description In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source c ...

  2. RabbitMQ Management HTTP API--官方文档

    Introduction Apart from this help page, all URIs will serve only resources of type application/json, ...

  3. linux安装tomcat(转载:http://blog.csdn.net/zhuihunmiling/article/details/8977387)

    在安装Tomcat之前需要安装j2sdk(Java 2 Software Development Kit),也就是JDK 1.安装JDK完毕. 2.安装Tomcat 1)下载apache-tomcat ...

  4. UI实时预览最佳实践(转)

    UI实时预览最佳实践 概要:Android中实时预览UI和编写UI的各种技巧.本文的例子都可以在结尾处的示例代码中看到并下载.如果喜欢请star,如果觉得有纰漏请提交issue,如果你有更好的点子可以 ...

  5. Git和Github的应用与命令方法总结

    title: Git和Github的应用与命令方法总结 date: 2016-07-11 14:03:09 tags: git/github [本文摘抄自微信公众平台:AndroidDeveloper ...

  6. 使用ef code first模式,在部署后服务器端把数据库同步到最新版本的方法

    共有两种方法: 1.使用migrate.exe 具体使用方法请参考 msdn migrate使用方法,这里只做介绍 复制migrate.exe 在使用 NuGet 安装实体框架时,migrate.ex ...

  7. makecert 制作数字证书

    在MS的SDK6.0中有个证书生成工具makecert.exe, 你可以使用这个工具来生成测试用的证书. 第一步,生成一个自签名的根证书(issuer,签发者). >makecert -n &q ...

  8. Linux2.6的所有内核版本

    Index of /pub/linux/kernel/v2.6 Name Last modified Size Parent Directory - incr/ 03-Aug-2011 20:47 - ...

  9. 移动端web开发调试

    手机上安装chrome, 连接上usb允许调试,打开电脑的chrome,输入chrome://inspect 点击电脑页面的inspect即可,这时操作手机和电脑能达到同步显示. android4.4 ...

  10. Semaphore (通常用于限制可以访问某些资源(物理或逻辑的)的线程数目)

    Semaphore 通常用于限制可以访问某些资源(物理或逻辑的)的线程数目.例如,下面的类使用信号量控制对内容池的访问: 方法详解: 构造方法摘要 Semaphore(int permits)     ...