其他分享
首页 > 其他分享> > POJ-2100 Graveyard Design

POJ-2100 Graveyard Design

作者:互联网

Graveyard Design

找到所有的区间,使得区间平方和为n

尺取

注意退出的边界

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 2e5 + 10;
const ll inf = 1e17 + 10;
vector<int>ans[maxn];

int main()
{
    ll n;
    while(scanf("%lld", &n) != EOF)
    {
        ll l = 1, r = 1, now = 0;
        int cnt = 0;
        while(1)
        {
            while(now < n)
            {
                now += r * r;
                r++;
            }
            if(r - l == 1 && now > n) break;
            if(now == n)
            {
                ans[cnt].clear();
                for(int i=l; i<r; i++)
                    ans[cnt].push_back(i);
                cnt++;
            }
            now -= l * l;
            l++;
        }
        printf("%d\n", cnt);
        for(int i=0; i<cnt; i++)
        {
            printf("%d", ans[i].size());
            for(int j=0; j<ans[i].size(); j++)
                printf(" %d", ans[i][j]);
            printf("\n");
        }
    }
    return 0;
}

标签:now,include,const,int,ll,while,POJ,Design,2100
来源: https://www.cnblogs.com/dgsvygd/p/16265198.html