Graveyard Design
Time Limit: 10000MS   Memory Limit: 64000K
Total Submissions: 6107   Accepted: 1444
Case Time Limit: 2000MS

Description

King George has recently decided that he would like to have a new design for the royal graveyard. The graveyard must consist of several sections, each of which must be a square of graves. All sections must have different number of graves.
After a consultation with his astrologer, King George decided that
the lengths of section sides must be a sequence of successive positive
integer numbers. A section with side length s contains s2
graves. George has estimated the total number of graves that will be
located on the graveyard and now wants to know all possible graveyard
designs satisfying the condition. You were asked to find them.

Input

Input file contains n --- the number of graves to be located in the graveyard (1 <= n <= 1014 ).

Output

On
the first line of the output file print k --- the number of possible
graveyard designs. Next k lines must contain the descriptions of the
graveyards. Each line must start with l --- the number of sections in
the corresponding graveyard, followed by l integers --- the lengths of
section sides (successive positive integer numbers). Output line's in
descending order of l.

Sample Input

2030

Sample Output

2
4 21 22 23 24
3 25 26 27 题意:给你一个数,询问有多少种连续自然数的平方和等于这个数,输出所有可能
题解:尺取法遍历所有符合条件的区间,满足的话记录左边界以及右边界,计数器+1。
尺取法过程:

  整个过程分为4布:

    1.初始化左右端点

    2.不断扩大右端点,直到满足条件

    3.如果第二步中无法满足条件,则终止,否则更新结果

    4.将左端点扩大1,然后回到第二步

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
typedef long long LL;
LL n;
struct Node{
LL l,r;
}res[];
int main()
{
while(scanf("%lld",&n)!=EOF){ LL l=,r=;
LL len = (int)sqrt(n*1.0)+;
LL sum = ;
int cnt=;
while(l<=len){
while(r<=len&&sum<n){
sum+=r*r;
r++;
}
if(sum<n) break;
if(sum==n){
cnt++;
res[cnt].l = l;
res[cnt].r = r;
}
sum-=l*l;
l++;
}
printf("%d\n",cnt);
for(int i=;i<=cnt;i++){
printf("%d ",res[i].r-res[i].l);
for(int j=res[i].l;j<res[i].r-;j++){
printf("%d ",j);
}
printf("%d\n",res[i].r-);
}
}
return ;
}

最新文章

  1. Date.parse
  2. python——连接MySQL数据库
  3. vue之自定义指令directive
  4. c# List AddRange
  5. html知识2
  6. Nginx编译参数大全 configure参数中文详解
  7. Asp.net MVC中Route的理解
  8. 【CF493E】【数学】Vasya and Polynomial
  9. 【转】NDK编译可执行文件在Android L中运行显示error: only position independent executables (PIE) are supported.失败问题解决办法。
  10. 关于url拼接传参数和利用view的字典传参数时,模板获取数据的方式问题
  11. Android设备管理器漏洞2--禁止用户取消激活设备管理器
  12. 20165306 Exp4 恶意代码分析
  13. L1-060 心理阴影面积
  14. 06_Hadoop分布式文件系统HDFS架构讲解
  15. HomeBrew 安转beta版软件
  16. Codeforce 294A - Shaass and Oskols (模拟)
  17. mysql 5.17 的update失败问题
  18. git初级浅入其常用操作
  19. 网络编程(socket,套接字)
  20. 个人项目-词频统计(语言:C++)

热门文章

  1. The Tower of Babylon UVA - 437 DAG上的动态规划
  2. Spring---环境搭建与包介绍
  3. 第三模块 面向对象&amp; 网络编程基础 实战考核
  4. oracle常用关键字和函数
  5. Atom-无懈可击的Markdown编辑器
  6. 聊聊、Spring 数据源
  7. c++ 运算符重载operator
  8. 【转】深入理解 C# 协变和逆变
  9. 目前问题:plupload上传带参数到后台
  10. html5中checkbox的选中状态的设置与获取