HDU 4982/BC 6B Goffi and Squary Partition
来源:互联网 发布:淘宝店铺都多大尺寸 编辑:程序博客网 时间:2024/05/21 05:22
题面大意 给定n,k问是否有k个不同正整数 和为n 且其中k-1个数 是某个数的平方数
设 k-1个数等于 i²,每次从大到小枚举i,看是否存在合法的,由于k个数 必须不同,所以 出来k-1个数 剩下一个数 z=n-i²。当z>k时 k-1个数从1 到k-1 排列,只要比i²小,比i²小的部分 可以从大到小 不断加一的方式 来完美的 凑出所以比 k(k-1)/2大的所有数。但当z=k时,k-1个数从1 到k-1 排列,由于不能和已经确定的z值冲突,无法形成 比k(k-1)/2正好大一的数 ,特判下即可。z<k时,把z混到k中即可。
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#include<stack>#include<bitset>#define inf 0x3f3f3f3f#define ll long long#define mod 1000000007using namespace std;#define bug puts("bugbugubgbugbug");int go(int n,int m,int z){ if(z<=0)return 0; if(z>m) { m--; if(m*(m+1)/2<=n-z) return 1; return 0; } else { if(z==m) { if(m*(m+1)/2==n-1) return 0; } if(m*(m+1)/2<=n) return 1; return 0; }}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { int flag=0; int z=sqrt(n); while((z+1)*(z+1)<=n)z++; for(int i=z;i>=1;i--) if(go(n,m,n-i*i)) { flag=1; break; } if(flag)puts("YES"); else puts("NO"); }}
0 0
- HDU 4982/BC 6B Goffi and Squary Partition
- Goffi and Squary Partition-HDU-4982 BC.6.B
- 【CUGBACM15级BC第六场 B】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)
- bc第六场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(思路)
- 【杂题】 HDOJ 4982 Goffi and Squary Partition
- HDOJ 4982 Goffi and Squary Partition
- [BestCoder Round #6] hdu 4982 Goffi and Squary Partition(构造)
- HDU 4982 Goffi and Squary Partition(BestCoder Round #6 1002)
- unity3d引擎架构之Componet
- sizeof(struct)分析(包括union)
- 重学C++ (一)
- poj解题报告——1023
- 暑假集训第三周第二阶段搜索 G - 迷宫问题
- HDU 4982/BC 6B Goffi and Squary Partition
- http://blog.csdn.net/hellowxwworld/article/details/10720765
- OC_NSString和NSMutableString
- hdoj5334
- GitHub 使用教程图文详解
- HDU 1695 GCD 莫比乌斯第二发
- svn服务器搭建
- eigen的基础配置 以及 cmake下cgal的demo&examples下的配置
- ShellExecute用法种种