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;
    }
  • 相关阅读:
    三维拓扑排序好题hdu3231
    hdu1811 拓扑排序+并查集缩点
    拓扑排序基础 hdu1258,hdu2647
    uva11827 处理下输入
    poj2116 模拟题
    exgcd求解同余方程的最小正整数解 poj1061 poj2115
    java Web应用配置log4j日志记录
    response.sendRedirect()重新定向的乱码问题
    JavaWeb学习之Servlet(四)----ServletConfig获取配置信息、ServletContext的应用
    JavaWeb学习之Servlet(三)----Servlet的映射匹配问题、线程安全问题
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/7276921.html
Copyright © 2011-2022 走看看