zoukankan      html  css  js  c++  java
  • Graveyard Design POJ

       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 s 2 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 <= 10 14 ).

    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 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<string>
     5 #include<cstring>
     6 #include<cmath>
     7 #define MAX 10000005
     8 using namespace std;
     9 typedef long long ll;
    10 
    11 ll n;
    12 ll a[MAX],b[MAX],c[MAX];
    13 
    14 int main()
    15 {  while(~scanf("%lld",&n)){
    16        int temp=sqrt(n)+1;
    17        ll l=1,r=1,t=0;    //用long long!!!调了一个多小时。。。 
    18        ll ans=0;
    19        while(r<=temp){
    20               if(r*r>n) break;
    21               ans+=r*r;           
    22               while(ans>n){
    23                    ans-=l*l;
    24                    l++;
    25               }
    26               r++;
    27               if(ans==n){
    28                    t++;
    29                    b[t]=r;
    30                    c[t]=r-l;
    31               }
    32        }
    33        if(t==0) printf("0
    ");
    34        else{
    35            printf("%d
    ",t);
    36            for(int i=1;i<=t;i++){
    37                  printf("%lld",c[i]);
    38                  for(int j=c[i];j>0;j--) printf(" %lld",b[i]-j);
    39                  printf("
    ");
    40              }
    41        }    
    42    } 
    43 }
  • 相关阅读:
    jquery web 國際化
    Struts2 分割字符串标签s:generator
    (55) 销售锁货功能
    (54) 记录销售单修改详细
    (53) 动态列表自定义
    exe文件作为服务启动
    (52)KeyError错误
    (51) magento集成增加到款通知
    (50)与magento集成
    (49) odoo context操作
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/6754217.html
Copyright © 2011-2022 走看看