POJ:2100-Graveyard Design(尺取)
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
解题心得:
- 给你一个数,问你他可以由多少个连续数的平方和得到,输出第一行为方案数,然后每一行第一个数是由多少个连续数的平方和得到,然后是连续数。
- 直接跑尺取,满足尺取的两个特点。
#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(尺取)的更多相关文章
- poj 2100 Graveyard Design(尺取法)
Description King George has recently decided that he would like to have a new design for the royal g ...
- poj 2100 Graveyard Design
直接枚举就行了 #include<iostream> #include<stdio.h> #include<algorithm> #include<ioman ...
- POJ 2566 Bound Found 尺取 难度:1
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 1651 Accepted: 544 Spec ...
- POJ:2566-Bound Found(尺取变形好题)
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5408 Accepted: 1735 Special J ...
- Subsequence (POJ - 3061)(尺取思想)
Problem A sequence of N positive integers (10 < N < 100 000), each of them less than or equal ...
- POJ 2100:Graveyard Design(Two pointers)
[题目链接] http://poj.org/problem?id=2100 [题目大意] 给出一个数,求将其拆分为几个连续的平方和的方案数 [题解] 对平方数列尺取即可. [代码] #include ...
- POJ2100 Graveyard Design(尺取法)
POJ2100 Graveyard Design 题目大意:给定一个数n,求出一段连续的正整数的平方和等于n的方案数,并输出这些方案,注意输出格式: 循环判断条件可以适当剪支,提高效率,(1^2+2^ ...
- poj 2100(尺取法)
Graveyard Design Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 6107 Accepted: 1444 ...
- B - Bound Found POJ - 2566(尺取 + 对区间和的绝对值
B - Bound Found POJ - 2566 Signals of most probably extra-terrestrial origin have been received and ...
随机推荐
- 关于jqeury中attr()和prop()方法
在平时工作中老会被一样的问题困住,浪费时间,这里做一个简要笔记. 在使用jquery给元素设置属性的时候,如果是一般的div,p等正常元素设置属性的话,使用attr()足以,但是在给拥有checked ...
- Python:Tkinter的GUI设计——物体实时移动
参考: 1.Tkinter之Canvas篇 2.python GUI实践:做一个满图乱跑的小球 3.[Tkinter 教程08] Canvas 图形绘制 4.tkinter模块常用参数(python3 ...
- 【Android 界面效果46】自定义view常处理的回调方法
onFinishInflate() 当View中所有的子控件均被映射成xml后触发 onMeasure(int, int) 确定所有子元素的大小 onLayout(boolean, int, int, ...
- ASP.NET 页面之间传递参数方法
1.通过URL链接地址传递 (1) send.aspx代码 protected void Button1_Click(object sender, EventArgs e) { Request.Red ...
- java学习笔记之基础知识
1.class不加修饰符默认default,只在当前包里能用. 2.构造函数前面的修饰符的作用类似class的,限制引用的权限. 3.java对象的创建其实就是类的实例化,类的实例化就是在堆上copy ...
- 【Troubleshooting 】Outlook 客户端无法显示电子邮件图像
出于安全原因,Outlook 2013/2016不会在电子邮件中显示图像,但您可以右键单击图像并选择" 下载图片 "选项.我最近注意Outlook停止显示图像,并且没有下载图像的选 ...
- 光标显示样式 css 中 cursor 属性使用
记录一下 cursor 的各种样式,方便自己查找.之前用到不常用的每次去 百度 或 Google 找不如自己记录下好找些. cursor光标类型 auto default none context-m ...
- 类型信息(RTTI和反射)——反射
运行时类型信息可以让你在程序运行时发现和使用类型信息. 在Java中运行时识别对象和类的信息有两种方式:传统的RTTI,以及反射.下面就来说说反射. 重点说说通过反射获取方法以及调用方法,即类方法提取 ...
- js从入门到精通到深入到就业
本篇博客是我参看人家代码做的总结,个人感觉非常非常好,简单.步步深入,不用花大量时间来学完正本js,只需要把其中的代码理解透彻,上班无压力(上班无压力是指js部分,包括查看框架源代码都有很大帮助) / ...
- java线程详细版(未完待续)
1. Java线程:概念与原理 一.操作系统中线程和进程的概念 现在的操作系统是多任务操作系统.多线程是实现多任务的一种方式. 进程是指一个内存中运行的应用程序,每个进程都有自己独立的一块内存空间,一 ...