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.

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
 
尺取法
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long ll;
typedef pair<ll,ll> pii; #define maxn 1000000 ll n;
pii ans[maxn]; int main()
{
// freopen("sw.in","r",stdin); while(~scanf("%I64d",&n)) {
ll s = ,pos = ,sum = ;
int len = ;
for(;s * s <= n; ++s) {
while(sum < n) {
sum += pos * pos;
++pos;
}
if(sum == n) {
ans[len].first = pos - s;
ans[len++].second = s;
}
sum -= s * s;
} printf("%d\n",len);
for(int i = ; i < len; ++i) {
printf("%I64d",ans[i].first);
for(int j = ; j < ans[i].first; ++j)
printf(" %I64d",ans[i].second + j);
printf("\n");
} } // cout << "Hello world!" << endl;
return ;
}

POJ 2100的更多相关文章

  1. POJ 2100:Graveyard Design(Two pointers)

    [题目链接] http://poj.org/problem?id=2100 [题目大意] 给出一个数,求将其拆分为几个连续的平方和的方案数 [题解] 对平方数列尺取即可. [代码] #include ...

  2. Greedy:Graveyard Design(POJ 2100)

    墓地 题目大意,给定一个整数,要你找出他的平方和组合 太简单了....不过一开始我储存平方和想降低时间,后来发现会超内存,直接用时间换空间了,游标卡尺法 #include <iostream&g ...

  3. poj 2100 Graveyard Design

    直接枚举就行了 #include<iostream> #include<stdio.h> #include<algorithm> #include<ioman ...

  4. poj 2100 Graveyard Design(尺取法)

    Description King George has recently decided that he would like to have a new design for the royal g ...

  5. poj 2100(尺取法)

    Graveyard Design Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 6107   Accepted: 1444 ...

  6. 尺取法 poj 2566

    尺取法:顾名思义就是像尺子一样一段一段去取,保存每次的选取区间的左右端点.然后一直推进 解决问题的思路: 先移动右端点 ,右端点推进的时候一般是加 然后推进左端点,左端点一般是减 poj 2566 题 ...

  7. ProgrammingContestChallengeBook

    POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...

  8. (完全背包 大数)Dollar Dayz (POJ 3181)

    http://poj.org/problem?id=3181 Description Farmer John goes to Dollar Days at The Cow Store and disc ...

  9. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

随机推荐

  1. C 实现一个简易的Http服务器

    引言 做一个老实人挺好的,至少还觉得自己挺老实的. 再分享一首 自己喜欢的诗人的一首 情景诗. 每个人总会有问题,至少喜欢就好, 本文 参照 http 协议   http://www.cnblogs. ...

  2. [转]关于VC预定义常量_WIN32,WIN32,_WIN64

      VC2012 下写 Windows 程序时,有时需要判断编译环境.在之前的文章<判断程序是否运行在 Windows x64 系统下.>里说过如何在运行期间判断系统环境,但在编译时如何判 ...

  3. 金融系列14《QPBOC交易流程》

    中国银行金融IC卡qPBOC交易时间(不含终端处理时间)要求:IC卡私钥长度1024位,交易时间 <= 500ms, 1152 <=600 ATR=3B8D800100814D220886 ...

  4. Python字节流打包拆包

    Python提供了一个struct模块用于打包拆包 -------------------------------------------------------------------------- ...

  5. [超简洁]EasyQ框架-应对WEB高并发业务(秒杀、抽奖)等业务

    背景介绍 这几年一直在摸索一种框架,足够简单,又能应付很多高并发高性能的需求.研究过一些框架思想如DDD DCI,也实践过CQRS框架. 但是总觉得复杂度高,门槛也高,自己学都吃力,如果团队新人更难接 ...

  6. 013--VS2013 C++ 地图贴图-其它格式图片

    //--------------------------------------------InitInstance() 函数------------------------------------- ...

  7. 不同系统间传输float型数据

    #include <stdio.h> #include <string.h> int main(void) { union result {          float d; ...

  8. Mono for Android (3)-- AbsoluteLayout、FrameLayout、LinearLayout、RelativeLayout、TableLayout

    AbsoluteLayout:允许开发人员将视图放在所定义的位置.该布局已经过时了,建议改用其他 FrameLayout:最简单的布局选项,其设计目的是在屏幕上显示单个对象.所有元素都固定在左上角.如 ...

  9. python3.4 安装ipython notebook

    1.安装python3.4 2.安装pyreadline 3.安装ipython-1.2.1.zip 4.安装pyzmq-14.7.0-cp34-none-win32.whl,ZIP包有问题,下载wh ...

  10. 20145129 《Java程序设计》第3周学习总结

    20145129 <Java程序设计>第3周学习总结 教材学习内容总结 类与对象 定义类 一个原始码中可以有多个类定义,但只有一个是公开类(public),并且文档中的主文档名必须和公开类 ...