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 }
  • 相关阅读:
    bzoj 1031: [JSOI2007]字符加密Cipher
    [BZOJ5011][JXOI2017]颜色
    [BZOJ4765]普通计算姬(分块+树状数组)
    [BZOJ3261]最大异或和(可持久化Trie)
    [BZOJ4861][BJOI2017]魔法咒语(AC自动机+矩阵优化DP)
    [BZOJ2286][SDOI2011]消耗战(虚树DP)
    [BZOJ2109][NOI2010]航空管制(贪心+拓扑)
    [BZOJ1305][CQOI2009]跳舞(网络流)
    [Nescafé41]编码病毒(循环卷积)
    [Nescafé41]异化多肽(多项式求逆元)
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/6754217.html
Copyright © 2011-2022 走看看