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. Python知识点入门笔记——特色数据类型(字典)

    Python中字典是一些列键 (key) 值 (value) 对组成的,形式如下 {键1:值1,键2:值:2} 每个键值对用冒号隔开,每对之间用逗号隔开 键必须是唯一的,必须是不可变的,如字符串,数字 ...

  2. 662. Maximum Width of Binary Tree

    https://leetcode.com/problems/maximum-width-of-binary-tree/description/ /** * Definition for a binar ...

  3. 2017 United Kingdom and Ireland Programming(Gym - 101606)

    题目很水.睡过了迟到了一个小时,到达战场一看,俩队友AC五个了.. 就只贴我补的几个吧. B - Breaking Biscuits Gym - 101606B 旋转卡壳模板题.然后敲错了. 代码是另 ...

  4. CountDownLatch、CyclicBarrier、Semaphore的区别

    在java 1.5中,提供了一些非常有用的辅助类来帮助我们进行并发编程,比如CountDownLatch,CyclicBarrier和Semaphore,今天我们就学习一下这三个辅助类的用法. 以下是 ...

  5. JDK各版本新特性浅谈

    JDK 5.0 自动拆装箱 枚举 可变参数 泛型 For -each 内省 静态导入 JDK 6.0 console开发控制台程序 轻量级HTTP ServerAPI 支持脚本语言 使用Compile ...

  6. Go语言之反射(二)

    反射的值对象 反射不仅可以获取值的类型信息,还可以动态地获取或者设置变量的值.Go语言中使用reflect.Value获取和设置变量的值. 使用反射值对象包装任意值 Go语言中,使用reflect.V ...

  7. B树、B-树、B+树、B*树之间的关系

    https://blog.csdn.net/u013411246/article/details/81088914

  8. 洛谷P1540 机器翻译

    题目链接:https://www.luogu.org/problemnew/show/P1540

  9. cf976d Degree Set

    ref #include <algorithm> #include <iostream> #include <cstdio> #include <vector ...

  10. 创建 PSO

    TechNet 库 Windows Server Windows Server 2008 R2 und Windows Server 2008 浏览 Windows Server 技术 Active ...