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 ...
随机推荐
- array_map()关于回调函数的总结
array_map()函数的第一个参数可以是匿名函数,系统函数,也可以是自己自定义的函!在全局空间下,这些函数的调用都很简单 在这里就不多说了!我们主要讨论的是该函数调用类中的方法和静态方法的区别 摘 ...
- 【起航计划 023】2015 起航计划 Android APIDemo的魔鬼步伐 22 App->Menu->Inflate from XML 使用xml资源展示菜单
本例MenuInflateFromXml.java演示了如何从Menu 资源(XML 定义)展开菜单项.这个例子的onCreate 采用了使用代码来创建Activity 界面的方法 而通常的方法是采用 ...
- python标准库 - socket
地址簇(address family) socket.AF_UNIX # (UNIX Domain Sockets) socket.AF_INET # ipv4 socket.AF_INET6 # i ...
- 仿照everything写的一个超级速查 原创
http://files.cnblogs.com/files/jacd/%E8%B6%85%E9%80%9F%E6%9F%A5%E6%96%87%E4%BB%B6.zip 速度奇快无比,体积奇小无比, ...
- c++的bind1st()与bind2nd() 二元算子转一元算子
bind1st()和bind2nd()是两个函数,用于将二元算子转成一元算子. 何谓二元算子? 比如< > =等等这些就是二元算子,即需要两个操作数的运算符. 何谓一元算子? 比如++ - ...
- jmter安装配置
一 JMeter 简介 JMeter 它是Apache组织的开放源代码项目,它是现在比较流行的功能和性能测试的工具.JMeter requires a fully compliant JVM 7 or ...
- POJ-3274 Gold Balanced Lineup---hash经典题!
题目链接: https://vjudge.net/problem/POJ-3274 题目大意: 给定多头牛的属性,每头牛的属性由一个非负数表示,该数的二进制表示不会超过K位,它的二进制表示的每一位若为 ...
- 【BZOJ3506】[CQOI2014] 排序机械臂(Splay)
点此看题面 大致题意: 给你\(n\)个数.第一次找到最小值所在位置\(P_1\),翻转\([1,P_1]\),第二次找到剩余数中最小值所在位置\(P_2\),翻转\([2,P_2]\),以此类推.求 ...
- 模拟猜数(POJ2328)
题目链接:http://poj.org/problem?id=2328 解题报告: 缩短区间,soeasy, #include <stdio.h> #include <stdlib. ...
- C语言函数申明关键字inline
内联inline是给编译器的优化提示,如果一个函数被编译成inline的话,那么就会把函数里面的代码直接插入到调用这个函数的地方,而不是用调用函数的形式.如果函数体代码很短的话,这样会比较有效率,因为 ...