poj 2100 Graveyard Design(尺取法)
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 s2graves. 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 ( <= n <= ).
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
Sample Output
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
vector< pair<ll,ll> >ans; int main()
{
ll n;
while(scanf("%I64d",&n)==){
ll s=,t=;
ll sum=;
for(;;){ while(sum<n){
sum=sum+t*t;
t++;
}
if((t-)*(t-)>n)
break;
if(sum==n){
ans.push_back(make_pair(s,t-));
}
sum-=s*s;
s++; }
ll m=ans.size();
printf("%I64d\n",m);
for(int i=;i<m;i++){
ll l=ans[i].first;
ll r=ans[i].second;
printf("%I64d",r-l+);
for(ll j=l;j<=r;j++){
printf(" %I64d",j);
}
printf("\n"); }
}
return ;
}
poj 2100 Graveyard Design(尺取法)的更多相关文章
- poj 2100 Graveyard Design
直接枚举就行了 #include<iostream> #include<stdio.h> #include<algorithm> #include<ioman ...
- poj 2566"Bound Found"(尺取法)
传送门 参考资料: [1]:http://www.voidcn.com/article/p-huucvank-dv.html 题意: 题意就是找一个连续的子区间,使它的和的绝对值最接近target. ...
- poj 3061(二分 or 尺取法)
传送门:Problem 3061 https://www.cnblogs.com/violet-acmer/p/9793209.html 马上就要去上课了,先献上二分AC代码,其余的有空再补 题意: ...
- POJ 2566 Bound Found(尺取法,前缀和)
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5207 Accepted: 1667 Spe ...
- POJ 3061 Subsequence ( 尺取法)
题目链接 Description A sequence of N positive integers (10 < N < 100 000), each of them less than ...
- poj 3320 复习一下尺取法
尺取法(two point)的思想不难,简单来说就是以下三步: 1.对r point在满足题意的情况下不断向右延伸 2.对l point前移一步 3. 回到1 two point 对连续区间的问题求 ...
- poj 2566 Bound Found 尺取法 变形
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2277 Accepted: 703 Spec ...
- POJ 3061 Subsequence ( 二分 || 尺取法 )
题意 : 找出给定序列长度最小的子序列,子序列的和要求满足大于或者等于 S,如果存在则输出最小长度.否则输出 0(序列的元素都是大于 0 小于10000) 分析 : 有关子序列和的问题,都可以考虑采用 ...
- poj 2566 Bound Found 尺取法
一.首先介绍一下什么叫尺取 过程大致分为四步: 1.初始化左右端点,即先找到一个满足条件的序列. 2.在满足条件的基础上不断扩大右端点. 3.如果第二步无法满足条件则到第四步,否则更新结果. 4.扩大 ...
随机推荐
- Javascript:sort()方法快速实现对数组排序
定义和用法: sort() 方法用于对数组的元素进行排序. 语法: arrayObject.sort(sortby) 注释:sortby,可选,规定排序顺序,必须是函数. 说明: 如果调用该方法时没有 ...
- google在线測试练习题1
Problem You receive a credit C at a local store and would like to buy two items. You first walk thro ...
- Java基础知识强化60:经典查找之二分查找
1. 二分查找 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表. 比较 ...
- Python的学习
1.psutil的安装 [root@YQY-TIAN- ~]# wget https://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.t ...
- fstab的格式
# /etc/fstab/dev/hda8 swap swap defaults 0 0/dev/hda9 / ext2 defaults 1 1/dev/hda6 /wine vfat defaul ...
- (转)检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(转)
我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.N ...
- 后台的Activity被系统回收怎么办?
onSaveIntanceState,当程序中的某个Activity A在运行中,主动或者被动的运行另外一个新的Activity B,这个时候 A就会执行onSaveIntanceState(Bund ...
- 推荐Mac软件Alfred
实在忍不住推荐这个软件了, 身边的朋友们逐渐都在使用Mac OS了,每次我都会推荐Alfred这个软件.推荐来推荐去挺蛮烦的,干脆写篇文章, 下次有朋友新入手Macbook,我就直接附送本文章链接一枚 ...
- HTML&CSS基础学习笔记1.26-input重置表单
重置表单 <input>的[type]属性值为"button"的时候表示一个普通的按钮,相当于一个<button>标签. <input>的[ty ...
- C程序设计语言练习题1-2
练习1-2 做个实验,当printf函数的参数字符串中包含\c(其中c是上面的转义字符串序列中未曾列出的某一个字符)时,观察一下会出现什么情况. 代码如下: #include <stdio.h& ...