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.扩大 ...
随机推荐
- Struts 2零配置
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该 ...
- lesson2:java阻塞队列的demo及源码分析
本文向大家展示了java阻塞队列的使用场景.源码分析及特定场景下的使用方式.java的阻塞队列是jdk1.5之后在并发包中提供的一组队列,主要的使用场景是在需要使用生产者消费者模式时,用户不必再通过多 ...
- 图表插件--jqplot交互演示样例
简单交互 在之前的学习中,我们已经能够绘制各种类型的图表,也能够给图表加入不同的组件,如标题.图例等等.但这些图表仅仅能用于展示数据,一旦希望对图表有所操作--比方查看数据明细--就显得束手无策了.事 ...
- Tips:javascript 图片放大和取得尺寸
1)获取图片尺寸 <img src="http://img.my.csdn.net/uploads/201309/03/1378223257_7957.jpg" alt=&q ...
- 苹果的HomeKit协议
苹果的HomeKit协议非常底层,其作用仅限于让iOS平台和家居设备能够相互“握手”,但“认识”之后,想要继续控制灯.空调等设备,仍然需要家电厂商在HomeKit的基础上进行二次开发.
- linux-ln命令
ln分为软链接和硬链接 1.软连接 -s ln -s /mnt/hgfs/SHARE hvshare2 相当于在当前目录下新建一个名为hvshare2的快捷方式指向/mnt/hgfs/SHARE路 ...
- bash:command not found
在linux下执行某一常用命令时,提示类似错误信息:bash:bash:command not found 原因是所执行的命令在当前系统环境变量里找不到路径. 例如:刚安装了openOffice时,执 ...
- 零基础学习云计算及大数据DBA集群架构师【Linux系统配置及网络配置2015年12月30日周三】
/Mon *************摘要************** 计划任务 )一次性计划任务 服务:atd 命令:at 服务存放文件:/etc/init.d/atd 系统配置文件:/etc/at. ...
- js框架页跳转
1.跳出框架,在父页面. <script type="text/javascript"> window.parent.frames.location.href=&quo ...
- (转)Facade模式
Facade模式要求一个子系统的外部与其内部的通信必须通过一个统一的Facade对象进行.Facade模式提供一个高层次的接口,使得子系统更易于使用. 就如同医院的接待员一样,Facade模式的Fac ...