poj2100还是尺取
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
Output
Sample Input
2030
Sample Output
2
4 21 22 23 24
3 25 26 27
题意:给你一个数,求连续的整数的平方和为这个整数的个数
题解:尺取
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=0x3f3f3f3f; ll ss[N],tt[N]; ll solve(ll x)//对x进行尺取
{
ll ans=,s=,t=,sum=;
while((t-)*(t-)<=x){//这里的范围一定要取好,刚开始取t<=x,结果tle了,然后取了t*t<=x,又wa了,因为t*t满足提议的时候会少算一种情况
while(sum<x&&(t-)*(t-)<=x){
sum+=(t*t);
t++;
}
// cout<<sum<<endl;
if(sum<x)break;
if(sum==x)
{
ss[ans]=s;
tt[ans]=t;
ans++;
}
sum-=(s*s);
s++;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll n,ans;
cin>>n;
ans=solve(n);
cout<<ans<<endl;
for(int i=;i<ans;i++)
{
cout<<tt[i]-ss[i];
for(int j=ss[i];j<tt[i];j++)
cout<<" "<<j;
cout<<endl;
}
return ;
}
poj2100还是尺取的更多相关文章
- Gym 100703I---Endeavor for perfection(尺取)
题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...
- NOJ 1072 The longest same color grid(尺取)
Problem 1072: The longest same color grid Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit in ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- poj2566尺取变形
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
- cf1121d 尺取
尺取,写起来有点麻烦 枚举左端点,然后找到右端点,,使得区间[l,r]里各种颜色花朵的数量满足b数组中各种花朵的数量,然后再judge区间[l,r]截取出后能否可以供剩下的n-1个人做花环 /* 给定 ...
- HDU 5178 pairs【二分】||【尺取】
<题目链接> 题目大意: 给定一个整数序列,求出绝对值小于等于k的有序对个数. 解题分析: $O(nlong(n))$的二分很好写,这里就不解释了.本题尺取$O(n)$也能做,并且效率很不 ...
随机推荐
- 100本最棒的web前端图书推荐
前端技术,要学习的内容太多了,当你不知道从哪里开始的时候,你就先从看书开始,边看书边码代码,这个是学习编程必须的过程,因为你看一百遍,还不如自己写一遍,写一遍,第一可以加印象,第二便于更好的理解. 熟 ...
- 重启osd服务失败:Start request repeated too quickly
背景 OS:Ubuntu 16.04 修改了osd的一些配置,修改后,需要重启osd服务才能生效.第一次重启后,配置立刻生效.再改了一些配置,重启osd服务后,配置却不再生效了.ps命令查看进程,发现 ...
- 【Android】TextView文字长度测量和各种Paddding解析
老规矩,先上张图 o,这篇好像是分析篇,没有效果图.不管了,位置占着,老规矩不能坏,下面开始正文. *** 这篇博客会讲得比较杂: TextView里各部分的大小该怎么测量? 如何计算每行文字的长度? ...
- 在js中,window != top 的作用
在网站的首页加上下面的javascript,就可以把自己的窗口变成是最前端的窗口.可以避免别人把你的网站放在他的iframe中,显示的就是他的网站了,误导浏览者. <script type=&q ...
- iOS开发之Autolayout
1.概述 在以前的iOS程序中,是如何设置布局UI界面的? (1)经常编写大量的坐标计算代码 (2)为了保证在3.5 inch和4.0 inch屏幕上都能有完美的UI界面效果,有时还需要分别为2种屏幕 ...
- ORA-01994: GRANT failed: password file missing or disabled
1.错误现象 SQL> grant sysdba to test;grant sysdba to test*ERROR at line 1:ORA-01994: GRANT failed: pa ...
- java里的日期时间
为了更好理解java的日期时间类,在这里我们先介绍一下关于历法.标准时间的一些概念. 历法有很多种,我们大中华上下五千年,自然也有自己的历法,生活中我们通常把自己传统的历法叫做农历,也有人叫它阴历或夏 ...
- linux ssh -l 命令运用
ssh是远程登录命令,-l选项是最常用的选项,下面是我的一些总结 远程登录:ssh -l userName ip # 远程登录到 10.175.23.9 ssh -l root2 10.175. ...
- Android Weekly Notes Issue #251
Android Weekly Issue #251 April 2nd, 2017 Android Weekly Issue #251. 本期内容: Android O新增的API: View的too ...
- JS中遍历语法的比较
for循环 JavaScript 提供多种遍历语法.最原始的写法就是for循环.(假设myArray是数组,下面同理) let arr = [1,2,3,4,5]; for (var index = ...