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 ;
}

poj 2100(尺取法)的更多相关文章

  1. POJ 3320 尺取法,Hash,map标记

    1.POJ 3320 2.链接:http://poj.org/problem?id=3320 3.总结:尺取法,Hash,map标记 看书复习,p页书,一页有一个知识点,连续看求最少多少页看完所有知识 ...

  2. POJ 3320 尺取法(基础题)

    Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently s ...

  3. POJ 3320 (尺取法+Hash)

    题目链接: http://poj.org/problem?id=3320 题目大意:一本书有P页,每页有个知识点,知识点可以重复.问至少连续读几页,使得覆盖全部知识点. 解题思路: 知识点是有重复的, ...

  4. POJ 2566 尺取法(进阶题)

    Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4297   Accepted: 1351   Spe ...

  5. poj 3320(尺取法)

    传送门:Problem 3320 参考资料: [1]:挑战程序设计竞赛 题意: 一本书有 P 页,每页都有个知识点a[i],知识点可能重复,求包含所有知识点的最少的页数. 题解: 相关说明: 设以a[ ...

  6. poj 2100 Graveyard Design(尺取法)

    Description King George has recently decided that he would like to have a new design for the royal g ...

  7. 尺取法 poj 2566

    尺取法:顾名思义就是像尺子一样一段一段去取,保存每次的选取区间的左右端点.然后一直推进 解决问题的思路: 先移动右端点 ,右端点推进的时候一般是加 然后推进左端点,左端点一般是减 poj 2566 题 ...

  8. POJ 尺取法

    poj3061 Subsequence 题目链接: http://poj.org/problem?id=3061 挑战P146.题意:给定长度为n的数列整数a0,a1,...,a(n-1)以及整数S, ...

  9. POJ 3061 (二分+前缀和or尺取法)

    题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点 ...

随机推荐

  1. linux Ubuntu18.04 安装配置MySQL

    1.安装 ubuntu上安装mysql非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server   2. apt-get install mysql ...

  2. 快速排序,对于相同元素的优化,c++

    #include<iostream>using namespace std; void middl(int &p,int &q,int &r)//找枢轴,然后把枢轴 ...

  3. Diycode开源项目 LoginActivity分析

    1.首先看一下效果 1.1.预览一下真实页面 1.2.分析一下: 要求输入Email或者用户名,点击编辑框,弹出键盘,默认先进入输入Email或用户名编辑框. 点击密码后,密码字样网上浮动一段距离,E ...

  4. Python之print函数详解

    输出的 print 函数总结: 1. 字符串和数值类型可以直接输出 >>> print(1) 1 >>> print("Hello World" ...

  5. 2.使用vue ui命令快速构建应用

    直接在web端新建应用 C:\Users\Hugo> vue ui

  6. Django 六——自定义标签、图片验证码、发送邮件、评论树、组合搜索

    1.自定义标签 2.图片验证码 3.生成邮箱验证码.发送邮件 4.评论树实现 5.组合搜索(Q) 1.自定义标签 配置: a.在app中新建文件夹  templatetags,里面新建  xx.py文 ...

  7. msconfig.exe

    msconfig.exe 编辑 本词条缺少概述.名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧!   中文名 微软系统配置实用程序 外文名 msconfig.exe 出品者 Micros ...

  8. opendatasource问题

    EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO EXEC sp_configure 'Ad Hoc Distributed ...

  9. JVM虚拟机系列(三)Class文件格式

  10. RNQOJ 开心的金明

    题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过N 元钱就行”.今 ...