POJ 2100:Graveyard Design(Two pointers)
【题目链接】 http://poj.org/problem?id=2100
【题目大意】
给出一个数,求将其拆分为几个连续的平方和的方案数
【题解】
对平方数列尺取即可。
【代码】
#include <cstdio>
using namespace std;
typedef long long LL;
const int N=10000010;
LL n,ansl[N],ansr[N];
int main(){
while(~scanf("%lld",&n)){
LL l=1,r=0,s=0;int cnt=0;
for(;l*l<=n;s-=l*l,l++){
while((r+1)*(r+1)<=n&s<n){r++;s+=r*r;}
if(s==n){ansl[++cnt]=l;ansr[cnt]=r+1;}
}printf("%d\n",cnt);
for(int i=1;i<=cnt;i++){
printf("%lld",ansr[i]-ansl[i]);
for(int j=ansl[i];j<ansr[i];j++)printf(" %d",j);
puts("");
}
}return 0;
}
POJ 2100:Graveyard Design(Two pointers)的更多相关文章
- POJ 2566:Bound Found(Two pointers)
[题目链接] http://poj.org/problem?id=2566 [题目大意] 给出一个序列,求一个子段和,使得其绝对值最接近给出值, 输出这个区间的左右端点和区间和. [题解] 因为原序列 ...
- POJ:2100-Graveyard Design(尺取)
Graveyard Design Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 8504 Accepted: 2126 Cas ...
- POJ2100 Graveyard Design(尺取法)
POJ2100 Graveyard Design 题目大意:给定一个数n,求出一段连续的正整数的平方和等于n的方案数,并输出这些方案,注意输出格式: 循环判断条件可以适当剪支,提高效率,(1^2+2^ ...
- POJ 2796:Feel Good(单调栈)
http://poj.org/problem?id=2796 题意:给出n个数,问一个区间里面最小的元素*这个区间元素的和的最大值是多少. 思路:只想到了O(n^2)的做法. 参考了http://ww ...
- POJ 3318:Matrix Multiplication(随机算法)
http://poj.org/problem?id=3318 题意:问A和B两个矩阵相乘能否等于C. 思路:题目明确说出(n^3)的算法不能过,但是通过各种常数优化还是能过的. 这里的随机算法指的是随 ...
- POJ 1200:Crazy Search(哈希)
Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32483 Accepted: 8947 Des ...
- poj 2100 Graveyard Design(尺取法)
Description King George has recently decided that he would like to have a new design for the royal g ...
- POJ 3026 : Borg Maze(BFS + Prim)
http://poj.org/problem?id=3026 Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3301:Texas Trip(计算几何+三分)
http://poj.org/problem?id=3301 题意:在二维平面上有n个点,每个点有一个坐标,问需要的正方形最小面积是多少可以覆盖所有的点. 思路:从第二个样例可以看出,将正方形旋转45 ...
随机推荐
- postman导出excel出现response
https://jingyan.baidu.com/article/915fc414559b4351394b2084.html
- 仅需几行代码 轻松实现ETH代币空投
仅需几行代码 轻松实现ETH代币空投 批量发送以太坊,部署下面的合约,然后往下面的合约打币,就可以分发 ragma solidity ^0.4.21; contract batchTransfer { ...
- 网络--路由表&IP选路
路由表的 flags 字段显示路由状态: A 活动的休眠网关检测在路由上被启用.本字段只适用于 AIX 5.1 或更新版本. U :Up. H :路由至主机而不是网络. G :路由至网关. 不带G表示 ...
- 转:sift算法详解
转自:http://blog.csdn.net/pi9nc/article/details/23302075 对于初学者,从David G.Lowe的论文到实现,有许多鸿沟,本文帮你跨越. 1.SIF ...
- c#中RadioButtonList选中后不整体刷新页面保持选中状态
c#中用asp的RadioButtonList控件总会遇到选中了,然后跟着就刷新整体页面,又变为没有选中状态. <%@ Page Language="C#" AutoEven ...
- lua中是 ffi 解析 【是如何处理数据包的/pkt是如何传进去的】 fsfsfs
lua中的ffi是如何解析的呢? 拿bcc中对proto的解析说起: metatype是有大学问的: ffi.metatype(ffi.typeof('struct ip_t'), { __index ...
- 内存检测工具valgrind
valgrind --tool=memcheck --leak-check=full --error-limit=no --trace-children=yes ./server valgrind ...
- NBUT校赛 J Alex’s Foolish Function(分块+延迟标记)
Problem J: Alex’s Foolish Function Time Limit: 8 Sec Memory Limit: 128 MB Submit: 18 Solved: 2 Des ...
- [codeforces934E]A Colourful Prospect
[codeforces934E]A Colourful Prospect 试题描述 Firecrackers scare Nian the monster, but they're wayyyyy t ...
- BZOJ2879 [Noi2012]美食节 【费用流】
题目 CZ市为了欢迎全国各地的同学,特地举办了一场盛大的美食节.作为一个喜欢尝鲜的美食客,小M自然不愿意错过这场盛宴.他很快就尝遍了美食节所有的美食.然而,尝鲜的欲望是难以满足的.尽管所有的菜品都很可 ...