POJ:2100-Graveyard Design(尺取)

时间:2022-09-23 19:58:50

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 尺取 难度&colon;1

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

  4. POJ:2566-Bound Found&lpar;尺取变形好题&rpar;

    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&lpar;尺取法&rpar;

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

  9. B - Bound Found POJ - 2566&lpar;尺取 &plus; 对区间和的绝对值

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

随机推荐

  1. MyEclipse中SVN的常见的使用方法

    本次主要内容: 一 .导入项目 (Checkout).从svn资源库检出 二 .更新 (Update) 三.锁(对要修改的文件加锁,防止文件冲突) 四.提交(项目修改后的提交) 五.解锁 六.查看历史 ...

  2. 《Apache之访问本地用户家目录》——RHEL6&period;3

    首先保证这个本地用户是系统上有的. 1.安装httpd软件包: Yum install httpd 2.启动apache服务: 3.配置用户的家目录: 4.打开apache访问家目录的权限: 5.配置 ...

  3. JS浏览器对象-Location对象

    1.返回web主机的域名 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  4. Linux: 信息查看

    Linux log日志查看  http://www.2cto.com/os/201307/227230.html

  5. redis键操作

    设置键 [root@host ~]# /usr/local/redis/bin/redis-cli 127.0.0.1:6379> set name linux OK 127.0.0.1:637 ...

  6. 输入docker ps 报错信息处理Get http&colon;&sol;&sol;&sol;var&sol;run&sol;docker&period;sock&sol;v1&period;19&sol;containers&sol;json&colon; dial unix &sol;var&sol;run&sol;docker&period;sock&colon; permission denied&period;

    完整错误信息 Get http:///var/run/docker.sock/v1.19/containers/json: dial unix /var/run/docker.sock: permis ...

  7. MongoDB 和 NoSQL简介

    MongoDB 是一个基于分布式文件存储的数据库( https://www.mongodb.com/ ).由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案.MongoDB ...

  8. ubuntu linux修改文件所属用户&lpar;owner属主&rpar;和组&lpar;groud属组、用户组&rpar;

    使用chown命令可以修改文件或目录所属的用户: 命令格式:sudo chown 用户 目录或文件名 例如:sudo chown -R griduser /home/dir1  (把home目录下的d ...

  9. js获取本机id

    var hostname = location.hostname; window.location.href="http://"+hostname+":8080/zhib ...

  10. 12&period;翻译系列:EF 6 中配置一对多的关系【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-f ...