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. Firewall Rule Properties Page: Advanced Tab

    Applies To: Windows 7, Windows Server 2008 R2 Use this tab to configure the profiles and interface t ...

  2. Python-S9-Day99——Web前端框架之Vue.js

    01课程安排 02let和const: 03 箭头函数 04 对象的单体模式 05 Node.js介绍和npm操作 06 Webpack,babel介绍和Vue的第一个案例 01课程安排 1.1 ht ...

  3. 爬虫:Scrapy1

    Python 2.7 npm install scrapy 步骤: 创建一个 Scrapy 项目 定义提取的 Item 编写爬取网站的 Spider 并提取 Item 编写 Item Pipeline ...

  4. [笔记]《算法图解》第十章 K最近邻算法

    K最近邻算法 简称KNN,计算与周边邻居的距离的算法,用于创建分类系统.机器学习等. 算法思路:首先特征化(量化) 然后在象限中选取目标点,然后通过目标点与其n个邻居的比较,得出目标的特征. 余弦相似 ...

  5. CI在nginx环境下去掉url中的index.php

    在nginx环境下CI框架默认URL规则访问不了,出现500错误,如: http://blog.php230.com/index.php/keywords 今天在服务器配置CI框架环境时,去除URL中 ...

  6. Pointcut is not well-formed: expecting 'identifier' at character position 0 ^ || Pointcut is not well-formed: expecting ')' at character position 11 ^

    错误提示: 解决方法1:指定execution 在执行目标方法之前指定execution 解决方法2:可能是execution写错了.请仔细检查. 其他——execution参数设置(带问好的可以不配 ...

  7. 【Luogu】P2491消防(单调队列)

    题目链接 首先可以想到路径一定是在直径上的. 然后对每个点dfs出不经过直径的以它开始的路径最大长度,记为dis 然后就可以求出直径之后枚举左右端点,设左端点l右端点r,直径上点距离直径上起点的距离用 ...

  8. SPOJ 422 Transposing is Even More Fun ——Burnside引理

    这题目就比较有趣了. 大概题目中介绍了一下计算机的储存方法,给一个$2^a*2^b$的矩阵. 求转置.但是只能交换两个数,求所需要的步数. 首先可以把变化前后的位置写出来,构成了许多的循环.左转将狼踩 ...

  9. 论文笔记《ImageNet Classification with Deep Convolutional Neural Network》

    一.摘要 了解CNN必读的一篇论文,有些东西还是可以了解的. 二.结构 1. Relu的好处: 1.在训练时间上,比tanh和sigmod快,而且BP的时候求导也很容易 2.因为是非饱和函数,所以基本 ...

  10. jquery 实践操作:load()方法

    最近决定总结下实际项目中的 JS 相关的一些操作,因此开启此系列,记录使用过程中用到的一些实用操作问题和解决方法,给自己一份记录. jquery load方法是对jQuery.ajax()进行封装以方 ...