Graveyard Design

传送门

题面:

Graveyard Design

Time Limit: 10000MS
Memory Limit: 64000K
Total Submissions: 9489
Accepted: 2401
Case Time Limit: 2000MS

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 s 2 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 <= 10 14 ).

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

题面描述:

要求墓地由s*s个墓碑组成,找到k个连续的s使得这k个墓地的墓碑总数为n,这样的组合可能有多种,输出全部的可能并按k的个数降序排列。

题目分析:

基础的尺取题,双指针从1开始,前指针每到一个数sum就加上它的平方,当sum的值大于所求的值时后指针开始向前,每到一个数sum就减去它的平方,当sum等于所求值时保存一下前后指针。接着往下找直到结束。最后按保存好的前后指针的差值排序一下,从大到小输出就行。

代码:

#include<algorithm>
#include<stdio.h> 
#include<iostream>
using namespace std;

int main(){
	long long n,sum=0,i2=0,i3=0;//这里sum和i2,i3如果不用longlong后面数很大到1e14就判断不了了 
	int num1=0,num3=0,num2[1000]={0},i1[1000]={0},t1,t2;
	scanf("%lld",&n);
	while(i2<10000005){
		i2++,sum+=i2*i2,num3++;
		while(sum>n) i3++,sum-=i3*i3,num3--;
		if(sum==n) i1[num1]=i3+1,num2[num1]=num3,num1++;//这里不用i2++ 
	}
	printf("%d",num1);
	for(i2=0;i2<num1;i2++){
		printf("\n%d",num2[i2]);
		for(i3=0;i3<num2[i2];i3++) printf(" %d",i1[i2]++);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yjonben

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值