zoukankan      html  css  js  c++  java
  • POJ 2100

    Graveyard Design
    Time Limit: 10000MS   Memory Limit: 64000K
    Total Submissions: 4443   Accepted: 946
    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
     
    尺取法
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 typedef long long ll;
     9 typedef pair<ll,ll> pii;
    10 
    11 #define maxn 1000000
    12 
    13 ll n;
    14 pii ans[maxn];
    15 
    16 int main()
    17 {
    18    // freopen("sw.in","r",stdin);
    19 
    20     while(~scanf("%I64d",&n)) {
    21             ll s = 1,pos = 1,sum = 0;
    22             int len = 0;
    23             for(;s * s <= n; ++s) {
    24                     while(sum < n) {
    25                             sum += pos * pos;
    26                             ++pos;
    27                     }
    28                     if(sum == n) {
    29                             ans[len].first = pos - s;
    30                             ans[len++].second = s;
    31                     }
    32                     sum -= s * s;
    33             }
    34 
    35             printf("%d
    ",len);
    36             for(int i = 0; i < len; ++i) {
    37                     printf("%I64d",ans[i].first);
    38                     for(int j = 0; j < ans[i].first; ++j)
    39                             printf(" %I64d",ans[i].second + j);
    40                     printf("
    ");
    41             }
    42 
    43     }
    44 
    45    // cout << "Hello world!" << endl;
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    ubuntu
    long long 的输入输出问题
    hdu 4135 a到b的范围中多少数与n互质(容斥)
    hdu4757 可持续化01字典树+LCA
    E
    bzoj4260 求两个不相交的区间各自异或后相加的最大值。
    hdu4638 问一段区间能组成多少段连续的数
    hdu4637 计算俩运动对象的时间交
    hdu4632 回文子序列
    hdu4635 有向点双
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3623692.html
Copyright © 2011-2022 走看看