Graveyard Design

Time Limit: 10000MS Memory Limit: 64000K

Total Submissions: 8504 Accepted: 2126

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


解题心得:

  1. 给你一个数,问你他可以由多少个连续数的平方和得到,输出第一行为方案数,然后每一行第一个数是由多少个连续数的平方和得到,然后是连续数。
  2. 直接跑尺取,满足尺取的两个特点。

#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
vector < pair<ll,ll> > ve;
void solve(ll n) {
ll l = 1,r = 1,sum = 0; while(1) {
while(sum < n && r <= 1e7) {
sum += r*r;
r++;
}
if(sum < n)
break;
if(sum == n)
ve.push_back(make_pair(l,r-1));
sum -= l*l;
l++;
if(l*l > n)
break;
}
printf("%lld\n",ve.size());
for(ll i=0;i<ve.size();i++) {
printf("%d ",ve[i].second-ve[i].first+1);
for(ll j=ve[i].first;j<=ve[i].second;j++) {
if(j == ve[i].first)
printf("%lld",j);
else
printf(" %lld",j);
}
printf("\n");
}
} int main() {
ll n;
scanf("%lld",&n);
solve(n);
return 0;
}

POJ:2100-Graveyard Design(尺取)的更多相关文章

  1. poj 2100 Graveyard Design(尺取法)

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

  2. poj 2100 Graveyard Design

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

  3. POJ 2566 Bound Found 尺取 难度:1

    Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 1651   Accepted: 544   Spec ...

  4. POJ:2566-Bound Found(尺取变形好题)

    Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5408 Accepted: 1735 Special J ...

  5. Subsequence (POJ - 3061)(尺取思想)

    Problem A sequence of N positive integers (10 < N < 100 000), each of them less than or equal ...

  6. POJ 2100:Graveyard Design(Two pointers)

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

  7. POJ2100 Graveyard Design(尺取法)

    POJ2100 Graveyard Design 题目大意:给定一个数n,求出一段连续的正整数的平方和等于n的方案数,并输出这些方案,注意输出格式: 循环判断条件可以适当剪支,提高效率,(1^2+2^ ...

  8. poj 2100(尺取法)

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

  9. B - Bound Found POJ - 2566(尺取 + 对区间和的绝对值

    B - Bound Found POJ - 2566 Signals of most probably extra-terrestrial origin have been received and ...

随机推荐

  1. Python函数(1)

    一.Python函数介绍 函数时组织好的,可重复的,用来实现单一,或相关联功能的代码段. 函数的使用原则时先定义,后调用:事先准备工具的过程即函数的定义,遇到应用场景拿来当工具用即函数的调用. 函数的 ...

  2. rpm打包工具

    http://fedoraproject.org/wiki/How_to_create_an_RPM_package # rpm --showrc|grep _topdir -14: _builddi ...

  3. php的yii框架开发总结6

    MVC中的Controller部分,所有的controller类都是继承自Controller基类,基类里面包含actionAdmin-管理员,actionIndex-一般默认显示,actionVie ...

  4. zabbix3.0问题及解决方法

    一.问题:Zabbix agent on T2 is unreachable for 5 minutes         解决:1.进入zabbix service端 vim /etc/zabbix/ ...

  5. C盘空间太大,分区助手减小分区大小教程

    首先看一个需要缩小C盘或需要减少分区空间的一个例子:“我的电脑里C盘剩余空间为530GB,除了C盘外还有一个D盘,但D盘的空间不到30GB,另外还有两个隐藏分区,一个200MB,一个15GB.我想把C ...

  6. MySQL入门很简单: 1 数据库概述

    1. 数据库概述 1.1 数据存储方式: 1)人工管理阶段 2)文件系统阶段: 文件系统通过文件的存储路径和文件名称访问文件中的数据 3)数据库系统阶段:Oracle, SQL Server, MyS ...

  7. Altium_Designer如何快速寻找元件和封装

    初学Altium碰到最多的问题就是:不知道元件放在哪个库中.这里我收集了DXP2004常用元件库下常见的元件.使用时,只需在libary中选择相应元件库后,输入英文的前几个字母就可看到相应的元件了.通 ...

  8. mysql索引和正确使用方式

    一.索引类型 B树索引:大部分都是,因此B树的特性限制了索引如何使用:必须看看索引的正确使用限制(含组合索引的限制)http://blog.csdn.net/lovemdx/article/detai ...

  9. IOS transform的使用(移动,放大,旋转)

    @interface ViewController () - (IBAction)up; - (IBAction)big ; - (IBAction)leftRotate ; @property (n ...

  10. log4net为什么会打印两次?

    用“log4net 使用”做关键字在bing上搜索,点开排序第一的链接:http://33liuhongwei33.blog.163.com/blog/static/39923778201156101 ...