POJ 2100 Graveyard Design 尺取法
来源:互联网 发布:修改注册表优化弹道cf 编辑:程序博客网 时间:2024/05/09 15:27
Graveyard Design
Time Limit:10000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu 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
24 21 22 23 243 25 26 27
题意:给你一个数 求一个连续序列的元素的平方之和 等于这个数 输出数量 还有区间长度及各个元素
ACcode:
#include<iostream>#include<cstdio>#include<vector>#include<cmath>#include<algorithm>using namespace std;typedef long long LL;typedef pair<LL, LL>pii;vector<pii>v;int main(){long long n, k, ans = 0;while (scanf("%I64d",&n)!=EOF){k = sqrt(n); v.clear();LL l = 1, r = 1, cnt = 1;while (1){while (r <= k && cnt < n){r++;cnt += r*r;}if (cnt < n ) break;if (cnt == n){v.push_back(make_pair(l, r));}cnt -= l*l; l++;}LL len = v.size();printf("%I64d\n", len);for (int i = 0; i < len; i++){printf("%I64d", v[i].second - v[i].first + 1);for (LL j = v[i].first; j <= v[i].second ; j++){printf(" %I64d", j);}printf("\n");}}return 0;}
0 0
- POJ 2100 - Graveyard Design(尺取法)
- POJ - 2100 Graveyard Design(尺取法)
- POJ-2100Graveyard Design(尺取法)
- POJ 2100 Graveyard Design(尺取法)
- poj 2100 Graveyard Design(尺取法)
- POJ 2100 Graveyard Design 尺取法
- POJ - 2100 Graveyard Design(尺取法)
- POJ 2100 Graveyard Design(尺取法)
- POJ 2100 · Graveyard Design【尺取法】
- POJ 2100 Graveyard Design 尺取法(滑动窗口)
- POJ2100-Graveyard Design【尺取法】
- poj2100 Graveyard Design 尺取法
- POJ2100 Graveyard Design【尺取法】
- NUC1840 Graveyard Design【尺取法】
- poj-2100 Graveyard Design
- POJ 2100 Graveyard Design
- POJ 2100 Graveyard Design
- poj 2100 Graveyard Design
- OC 01 类和对象
- 漂亮的LightBox图片画廊插件开发
- AndroidStudio下jni开发
- POJ-3264 Balanced Lineup
- HDU 1412 {A} + {B}(STL)
- POJ 2100 Graveyard Design 尺取法
- 适配器与组合模式
- HDU 3549 Flow Problem
- 向量的点乘和叉乘
- MySQL常用指令积累
- oracle中 connect by prior 递归算法
- 友盟社会化组件iOS版使用评测
- 无需Flash无需依赖任何JS库实现文本复制与剪切
- linux kernel编译生成zImage过程详解