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.
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
尺取法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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\n",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("\n"); 41 } 42 43 } 44 45 // cout << "Hello world!" << endl; 46 return 0; 47 }