HDU - 2058 The sum problem(思路题)
题目:
Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M.
思路:
刚开始做写了一个尺取法,脑抽的一批。(这几天心情真的是颓的很,连带脑瓜也不好用了,抓紧调整~~~~)
其实可以根据等差数列求和公式求出这个子序列的长度的一个大致的范围为k=sqrt(2*m),然后根据m和k求出首项a1,然后将a1、k和m待会原来的式子看看等号是不是成立。
如果成立就打印区间[a1,a1+k-1]
代码:
#include <bits/stdc++.h>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define MAX 1000000000
#define mod 1000000000
#define FRE() freopen("in.txt","r",stdin)
#define FRO() freopen("out.txt","w",stdout)
using namespace std;
typedef long long ll;
typedef pair<char,char> P;
const int maxn = ;
ll m,n; int main() {
while(scanf("%lld%lld",&n,&m) && n) {
ll t = sqrt(*m),a1;
for(int i=t; i>=; i--) {
a1 = (*m-i*i+i)/(*i);
if(i*i+(*a1-)*i==*m) {
printf("[%lld,%lld]\n",a1,a1+i-);
}
}
puts("");
}
return ;
}
HDU - 2058 The sum problem(思路题)的更多相关文章
- HDU 2058 The sum problem(枚举)
The sum problem Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the ...
- 题解报告:hdu 2058 The sum problem
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 问题描述 给定一个序列1,2,3,...... N,你的工作是计算所有可能的子序列,其子序列的总 ...
- hdu 2058 The sum problem(简单因式分解,,)
Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-se ...
- HDU 2058 The sum problem
传送门 Description Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequen ...
- HDU 2058 The sum problem (数学+暴力)
题意:给定一个N和M,N表示从1到N的连续序列,让你求在1到N这个序列中连续子序列的和为M的子序列区间. 析:很明显最直接的方法就是暴力,可是不幸的是,由于N,M太大了,肯定会TLE的.所以我们就想能 ...
- hdu 2058 The sum problem(数学题)
一个数学问题:copy了别人的博客 #include<cstdio> #include<cstdlib> #include<cmath> int main() { ...
- HDU 2058 The sum problem 数学题
解题报告:可以说是一个纯数学题,要用到二元一次和二元二次解方程,我们假设[a,b]这个区间的所有的数的和是N,由此,我们可以得到以下公式: (b-a+1)*(a+b) / 2 = N;很显然,这是一个 ...
- HDOJ 2058 The sum problem
Problem Description Given a sequence 1,2,3,--N, your job is to calculate all the possible sub-sequen ...
- HDU 5832 A water problem 水题
A water problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
随机推荐
- P4412 [SHOI2004]最小生成树
传送门 不难发现,对于每一条树边肯定要减小它的权值,对于每一条非树边要增加它的权值 对于每一条非树边\(j\),他肯定与某些树边构成了一个环,那么它的边权必须大于等于这个环上的所有边 设其中一条边为\ ...
- BZOJ 1001 [BeiJing2006]狼抓兔子 (UVA 1376 Animal Run)
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 24727 Solved: 6276[Submit][ ...
- Ocelot(七)- 入门
入门 Ocelot仅适用于.NET Core,目前是为netstandard2.0构建的.如果Ocelot适合您,那么此文档可能会有用. .NET 安装NuGet包 使用nuget安装Ocelot及其 ...
- vi 和vim中的查找和替换
查找 命令模式输入 : /the-string-you-want-to-lookup 替换 命令模式输入 : s /from/to/
- SQL 初级教程学习(二)
1.SQL 语句从 "Websites" 表中选取头两条记录: SELECT * FROM Websites LIMIT 2; SELECT TOP 50 PERCENT * FR ...
- Poj 2947 widget factory (高斯消元解同模方程)
题目连接: http://poj.org/problem?id=2947 题目大意: 有n种类型的零件,m个工人,每个零件的加工时间是[3,9],每个工人在一个特定的时间段内可以生产k个零件(可以相同 ...
- _bzoj1014 [JSOI2008]火星人prefix【Splay】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1014 天,写kth()时,把判断条件k <= siz[ch[x][0]]错写成了k & ...
- AJPFX关于this用法和注意事项
this:代表对象.就是所在函数所属对象的引用.哪个对象调用了this所在的函数,this就代表哪个对象,就是哪个对象的引用.开发时在定义功能时,如果该功能内部使用到了调用该功能的对象,这时就用thi ...
- UnixTime的时间戳的转换
public static string XConvertDateTime(double unixTime) { System.DateTime time = System.DateTime.MinV ...
- sh/bash/csh/Tcsh/ksh/pdksh等shell本质区别
sh/bash/csh/Tcsh/ksh/pdksh等shell本质区别 1. Shell脚本的书写 在写Shell脚本时,往往第一行要注明用什么解释器来解释这个脚本. 如#!/bin/bash即用/ ...