标签:
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 (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
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<vector> 5 #include<algorithm> 6 using namespace std; 7 #define ll long long 8 vector< pair<ll,ll> >ans; 9 10 int main() 11 { 12 ll n; 13 while(scanf("%I64d",&n)==1){ 14 ll s=1,t=1; 15 ll sum=0; 16 for(;;){ 17 18 while(sum<n){ 19 sum=sum+t*t; 20 t++; 21 } 22 if((t-1)*(t-1)>n) 23 break; 24 if(sum==n){ 25 ans.push_back(make_pair(s,t-1)); 26 } 27 sum-=s*s; 28 s++; 29 30 } 31 ll m=ans.size(); 32 printf("%I64d\n",m); 33 for(int i=0;i<m;i++){ 34 ll l=ans[i].first; 35 ll r=ans[i].second; 36 printf("%I64d",r-l+1); 37 for(ll j=l;j<=r;j++){ 38 printf(" %I64d",j); 39 } 40 printf("\n"); 41 42 } 43 } 44 return 0; 45 }
poj 2100 Graveyard Design(尺取法)
标签:
原文地址:http://www.cnblogs.com/UniqueColor/p/4767568.html