poj 2100 Graveyard Design(尺取法)

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 s2graves. 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 ( <= n <=  ).

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


Sample Output


Source

Northeastern Europe 2004, Northern Subregion
 
尺取法,具体看代码
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
vector< pair<ll,ll> >ans; int main()
{
ll n;
while(scanf("%I64d",&n)==){
ll s=,t=;
ll sum=;
for(;;){ while(sum<n){
sum=sum+t*t;
t++;
}
if((t-)*(t-)>n)
break;
if(sum==n){
ans.push_back(make_pair(s,t-));
}
sum-=s*s;
s++; }
ll m=ans.size();
printf("%I64d\n",m);
for(int i=;i<m;i++){
ll l=ans[i].first;
ll r=ans[i].second;
printf("%I64d",r-l+);
for(ll j=l;j<=r;j++){
printf(" %I64d",j);
}
printf("\n"); }
}
return ;
}
上一篇:matlab学习


下一篇:IIS7禁止后台访问