zoukankan      html  css  js  c++  java
  • 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
    ",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("
    ");
        }
        return 0;
    }
  • 相关阅读:
    小甲鱼PE详解之输入表(导出表)详解(PE详解09)
    小甲鱼PE详解之输入表(导入表)详解2(PE详解08)
    小甲鱼PE详解之输入表(导入表)详解(PE详解07)
    小甲鱼PE详解之区块描述、对齐值以及RVA详解(PE详解06)
    小甲鱼PE详解之区块表(节表)和区块(节)续(PE详解05)
    小甲鱼PE详解之区块表(节表)和区块(节)(PE详解04)
    天大 ACM 1090. City hall
    C++中关于cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
    Integer Inquiry -TJU1112
    天大acm 题号1002 Maya Calendar
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/7276921.html
Copyright © 2011-2022 走看看