zoukankan      html  css  js  c++  java
  • poj 2100 Graveyard Design

                                                                                                                                                              Graveyard Design
    Time Limit: 10000MS   Memory Limit: 64000K
    Total Submissions: 6597   Accepted: 1588
    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

    题意:国王要建造墓地,墓地可以分n块区域(n=1,2...),且区域是线性排列的,区域从前到后依次分配连续自然数的平方块墓碑。现在给你需要放置的墓碑的总数,让你给出所有可能的分配情况。
    思路:尺取法。
    AC代码:
    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<algorithm>
    #include<vector>
    using namespace std;
    typedef unsigned long long ll;
    const int N_MAX = 100000;
    bool what;
    ll num;
    vector<pair<ll, ll>>answer;
    int main() {
        ll n;
        while (scanf("%lld", &n) != EOF) {
            num = 0;
            ll l = 1, r = 1, sum = 0;
            while (1) {
                for (;;) {
                    while ( r*r<=n&&sum < n) {
                        sum += r*r;
                        r++;
                    }
                    if (sum < n) {
                        what = 0;
                        break;
                    }
                    if (sum == n) {
                        /////记录数据
                        answer.push_back(make_pair(l,r-1));
                        /////
                        what = 1;
                        num++;
                        break;
                    }
                    sum -= l*l;
                    l++;
                }
                if (what) {
                    l++;
                    r = l;
                    sum = 0;
                }
                else break;
            }
            ///////
            printf("%lld
    ",num);
            for (vector<pair<ll, ll>>::iterator it = answer.begin(); it != answer.end(); it++) {
                printf("%lld",it->second-it->first+1);
                for (ll j =it->first; j <= it->second; j++)
                    printf("% lld", j);
                printf("
    ");
            }
            ///////////
        }
        return 0;
    }
  • 相关阅读:
    动态加载配置文件
    Split Full Name as First and Last
    MM03物料主数据视图中某些视图或者某些字段的控制方法
    如何用《老友记》学英语?
    FOR ALL ENTRIES IN的用法
    [转载]MBEWH表数据更新逻辑
    如何学习《六人行》??
    英语口语练习方法
    SAP收货时自动创建采购订单
    BAPI_PO_CREATE1 创建采购订单时价格的处理函数
  • 原文地址:https://www.cnblogs.com/ZefengYao/p/6480190.html
Copyright © 2011-2022 走看看