Time Limit: 10000MS | Memory Limit: 64000K | |
Total Submissions: 6107 | Accepted: 1444 | |
Case Time Limit: 2000MS |
Description
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
Output
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。
尺取法过程:
整个过程分为4布:
1.初始化左右端点
2.不断扩大右端点,直到满足条件
3.如果第二步中无法满足条件,则终止,否则更新结果
4.将左端点扩大1,然后回到第二步
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
typedef long long LL;
LL n;
struct Node{
LL l,r;
}res[];
int main()
{
while(scanf("%lld",&n)!=EOF){ LL l=,r=;
LL len = (int)sqrt(n*1.0)+;
LL sum = ;
int cnt=;
while(l<=len){
while(r<=len&&sum<n){
sum+=r*r;
r++;
}
if(sum<n) break;
if(sum==n){
cnt++;
res[cnt].l = l;
res[cnt].r = r;
}
sum-=l*l;
l++;
}
printf("%d\n",cnt);
for(int i=;i<=cnt;i++){
printf("%d ",res[i].r-res[i].l);
for(int j=res[i].l;j<res[i].r-;j++){
printf("%d ",j);
}
printf("%d\n",res[i].r-);
}
}
return ;
}
poj 2100(尺取法)的更多相关文章
-
POJ 3320 尺取法,Hash,map标记
1.POJ 3320 2.链接:http://poj.org/problem?id=3320 3.总结:尺取法,Hash,map标记 看书复习,p页书,一页有一个知识点,连续看求最少多少页看完所有知识 ...
-
POJ 3320 尺取法(基础题)
Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently s ...
-
POJ 3320 (尺取法+Hash)
题目链接: http://poj.org/problem?id=3320 题目大意:一本书有P页,每页有个知识点,知识点可以重复.问至少连续读几页,使得覆盖全部知识点. 解题思路: 知识点是有重复的, ...
-
POJ 2566 尺取法(进阶题)
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4297 Accepted: 1351 Spe ...
-
poj 3320(尺取法)
传送门:Problem 3320 参考资料: [1]:挑战程序设计竞赛 题意: 一本书有 P 页,每页都有个知识点a[i],知识点可能重复,求包含所有知识点的最少的页数. 题解: 相关说明: 设以a[ ...
-
poj 2100 Graveyard Design(尺取法)
Description King George has recently decided that he would like to have a new design for the royal g ...
-
尺取法 poj 2566
尺取法:顾名思义就是像尺子一样一段一段去取,保存每次的选取区间的左右端点.然后一直推进 解决问题的思路: 先移动右端点 ,右端点推进的时候一般是加 然后推进左端点,左端点一般是减 poj 2566 题 ...
-
POJ 尺取法
poj3061 Subsequence 题目链接: http://poj.org/problem?id=3061 挑战P146.题意:给定长度为n的数列整数a0,a1,...,a(n-1)以及整数S, ...
-
POJ 3061 (二分+前缀和or尺取法)
题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点 ...
随机推荐
-
用户引导页--- ScrollView的使用
一.首先第一步,写好用户轮播页的viewController,比如叫做LVUserGuideVC,关键代码是配置和scrollView和pageControl. (1)scrollView的设置 se ...
- label标签
-
【Qt】Qt之进程间通信(IPC)【转】
简述 进程间通信,就是在不同进程之间传播或交换信息.那么不同进程之间存在着什么双方都可以访问的介质呢?进程的用户空间是互相独立的,一般而言是不能互相访问的,唯一的例外是共享内存区.但是,系统空间却是“ ...
-
flask项目部署到阿里云 ubuntu16.04
title: flask项目部署到阿里云 ubuntu16.04 date: 2018.3.6 项目地址: 我的博客 部署思路参考: Flask Web开发>的个人部署版本,包含学习笔记. 开始 ...
-
poj-1028 -网页导航
Description Standard web browsers contain features to move backward and forward among the pages rece ...
-
dubbo-springboot入门级demo
1. dubbo-springboot入门级demo 1.1. 前言 最后一个做运维的朋友和我提起,他们公司想做个dubbo灰度发布的功能,而这个功能落到了他头上.在我的印象里,dubbo应该可以通过 ...
-
[Swift]LeetCode777. 在LR字符串中交换相邻字符 | Swap Adjacent in LR String
In a string composed of 'L', 'R', and 'X'characters, like "RXXLRXRXL", a move consists of ...
-
[USACO 06DEC]Milk Patterns
Description 题库链接 给定一个长度为 \(n\) 的字符串,求至少出现 \(k\) 次的最长重复子串,这 \(k\) 个子串可以重叠. \(1\leq n\leq 20000\) Solu ...
-
Altium CAED 国际认证操作题例题(含下载)
官网介绍页面 https://www.altium.com.cn/certification 共五套操作题 含资料 蓝奏云:https://www.lanzous.com/i2lj1ng 百度网盘:h ...
-
Chrome浏览器查看 iframe信息 OpenFrame
https://chrome.google.com/webstore/search/openframe?hl=zh-CN&_category=extensions 搜索 OpenFrame 添 ...