poj 2100 Graveyard Design

Posted 勿忘初心0924

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj 2100 Graveyard Design相关的知识,希望对你有一定的参考价值。

Graveyard Design
Time Limit: 10000MS   Memory Limit: 64000K
Total Submissions: 7357   Accepted: 1816
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

Source

Northeastern Europe 2004, Northern Subregion
/*
* @Author: Lyucheng
* @Date:   2017-08-02 16:43:37
* @Last Modified by:   Lyucheng
* @Last Modified time: 2017-08-02 21:22:15
*/
/*
 题意:给你一个10^14的范围内的n,让你判断有多少连续子序列的平方和是n

 思路:尺取
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define LL long long
#define INF 0xffffffff
#define MAXN 10000001

using namespace std;

LL n;
LL l,r;
LL _min;
LL pos;

struct  Node{
    int l,r;
    Node(){}
    Node(int _l,int _r):l(_l),r(_r){}
};
vector<Node>v;

void init(){
    v.clear();
    pos=0;
}

int main(){ 
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    scanf("%I64d",&n);
    int cnt=((int)sqrt(n*1.0)) +1;
    init();

    l=1,r=1;
    _min=INF;
    while(r*r<=n&&l*l<=n){
        while(pos<n&&r*r<=n){
            pos+=r*r;
            r++; 
        }
        while(pos>n){
            pos-=l*l;
            l++;
        }
        if(pos==n){
            v.push_back(Node((int)l,(int)r-1));
            pos-=l*l;
            l++;  
        }
    }
    int tol=v.size();
    printf("%d\n",tol);
    for(int i=0;i<tol;i++){
        printf("%d ",v[i].r-v[i].l+1);
        for(int j=v[i].l;j<=v[i].r;j++){
            printf(j==v[i].l?"%d":" %d",j);
        }
        printf("\n");
    }
    return 0;
}

 

以上是关于poj 2100 Graveyard Design的主要内容,如果未能解决你的问题,请参考以下文章

POJ2100 Graveyard Design(尺取法)

Greedy:Graveyard Design(POJ 2100)

LA 3708 && POJ 3154 Graveyard (思维)

poj2100还是尺取

poj2100(尺取法)

poj 2100 尺取法(尺度法)