POJ 2100
| Time Limit: 10000MS | Memory Limit: 64000K | |
| Total Submissions: 4443 | Accepted: 946 | |
| Case Time Limit: 2000MS | ||
Description
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
Output
Sample Input
2030
Sample Output
2
4 21 22 23 24
3 25 26 27
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long ll;
typedef pair<ll,ll> pii; #define maxn 1000000 ll n;
pii ans[maxn]; int main()
{
// freopen("sw.in","r",stdin); while(~scanf("%I64d",&n)) {
ll s = ,pos = ,sum = ;
int len = ;
for(;s * s <= n; ++s) {
while(sum < n) {
sum += pos * pos;
++pos;
}
if(sum == n) {
ans[len].first = pos - s;
ans[len++].second = s;
}
sum -= s * s;
} printf("%d\n",len);
for(int i = ; i < len; ++i) {
printf("%I64d",ans[i].first);
for(int j = ; j < ans[i].first; ++j)
printf(" %I64d",ans[i].second + j);
printf("\n");
} } // cout << "Hello world!" << endl;
return ;
}
POJ 2100的更多相关文章
- POJ 2100:Graveyard Design(Two pointers)
[题目链接] http://poj.org/problem?id=2100 [题目大意] 给出一个数,求将其拆分为几个连续的平方和的方案数 [题解] 对平方数列尺取即可. [代码] #include ...
- Greedy:Graveyard Design(POJ 2100)
墓地 题目大意,给定一个整数,要你找出他的平方和组合 太简单了....不过一开始我储存平方和想降低时间,后来发现会超内存,直接用时间换空间了,游标卡尺法 #include <iostream&g ...
- poj 2100 Graveyard Design
直接枚举就行了 #include<iostream> #include<stdio.h> #include<algorithm> #include<ioman ...
- 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 Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 6107 Accepted: 1444 ...
- 尺取法 poj 2566
尺取法:顾名思义就是像尺子一样一段一段去取,保存每次的选取区间的左右端点.然后一直推进 解决问题的思路: 先移动右端点 ,右端点推进的时候一般是加 然后推进左端点,左端点一般是减 poj 2566 题 ...
- ProgrammingContestChallengeBook
POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...
- (完全背包 大数)Dollar Dayz (POJ 3181)
http://poj.org/problem?id=3181 Description Farmer John goes to Dollar Days at The Cow Store and disc ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
随机推荐
- opengl基础学习专题 (三) 多边形绘制的几种样式
题外话 聪明人之所以不会成功,是由于他们缺乏坚韧的毅力. ——艾萨克·牛顿(1643年1月4日—1727年3月31日)英国 也许可以理解为 想更深一步的时候,坚持,努力和聪明缺一不可. 挺直腰杆在此向 ...
- C++类实现三维数组算法
在学习北京大学教授的<程序设计实习 / Practice on Programming>中,遇到了一个习题,花了很长时间研究,现在分享出来: 课题地址:https://class.cour ...
- AppCan教你从零开始做开发
经常收到类似这样的提问:新手开发APP,要怎么学?我有满屏幕的文档和视频,然而并没有什么卵用,因为我不知道该从哪看起……今天的主要内容是教大家,如何在AppCan移动平台创建应用,引擎插件选择.证书管 ...
- 十一、从头到尾彻底解析Hash 表算法
在研究MonetDB时深入的学习了hash算法,看了作者的文章很有感触,所以转发,希望能够使更多人受益! 十一.从头到尾彻底解析Hash 表算法 作者:July.wuliming.pkuoliver ...
- 发现了一个制作iOS图标的利器
我制作的第一个Swift Demo已经将近完工,今天的任务便是给它添加图标.不过Xcode中对图标尺寸的要求还真是严苛,若是制作iPhone和iPad通用的应用,总共需要12种尺寸的图标,这对于美工功 ...
- ExtJs桌面组件(DeskTop)
在desktop\js目录中包含了5个js文件,这5个js文件如下: 还有css样式表:desktop.css,图片素材 在这5个js文件中封装了用于模拟桌面的类,这些类如下: Ext.ux.Star ...
- ExtJS FormPanel不执行校验
经检查问题原因在于使用了 validator 属性. 使用validator属性,必须添加返回值.不添加返回值,就会出现FormPanel不执行校验的问题.
- SQL Server数据库学习笔记-E-R模型
实体(Entities)联系(Relationships)模型简称E-R模型也称E-R方法,是由P.P.Chen于1976年首先提出的.还有一个关键元素Attributes-属性,它提供不受任何数据库 ...
- 005--VS C++ 加载位图
//全局变量 HDC mdc; //--------------------------------------------InitInstance() 函数--------------------- ...
- 读《JavaScript语言精粹》的一些感言
最近看了<JavaScript语言精粹>,并且连着看了两遍,如果非要用言语形容的话,那我只能用4个字来形容:相见恨晚.其中的一些经验经过这么多年的摸索其实也了然,但是作者用这么浅薄的书把有 ...