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 ...
随机推荐
- win10下的jdk1.8安装
1 下载jdk 下一步就好 默认C盘最好 不要又中文 http://pan.baidu.com/s/1eSwvFA6(这里面有两个jdk 32位 64位) 看图 CLASSPATH: .;%JAVA ...
- json 获取属性值
ajax后台获取json数据 前台赋值.由于值太多 一个个写 val会类似的.因为直接字段值和 前台的标签id相同,这样只要循环结果集json赋值即可. 这里需要用到json的字段值 var data ...
- 无线 WIFI 的13个信道频率范围(转载)
转自:http://cnzhx.net/blog/13-channels-of-wifi/ 目前主流的无线WIFI网络设备不管是802.11b/g还是802.11b/g/n 一般都支持13个信道.它们 ...
- Linux 常用命令十六 文件权限管理
一.ls -l 各段含义 wang@wang:~/workpalce/threading$ ls -l 总用量 drwxrwxr-x wang wang 12月 : a -rw-rw-r-- wang ...
- CF449D Jzzhu and Numbers
题解 刚刚学习了高维前缀和 这道题就肥肠简单了 高维前缀和其实原理肥肠简单 就是每次只考虑一维,然后只做这一维的前缀和 最后求出的就是总前缀和了 那么对于这道题 也就很简单了 发现选择的所有数每一位都 ...
- Lomsat gelral cf-600e
http://codeforces.com/contest/600/problem/E 暴力启发式合并就行了 提示:set的swap的复杂度是常数,这方面可以放心 我先打了一个很naive的算法 #i ...
- 题解报告:hdu 1754 I Hate It(线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某 ...
- 转-解决Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'问题
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) Red Hat Enterpr ...
- js学习笔记-事件委托
通过事件委托,你可以把事件处理器绑定到父元素上,避免了把事件处理器添加到多个子级元素上.从而优化性能. 事件代理用到了事件冒泡和目标元素.而任何一个元素的目标元素都是一开始的那个元素. 这里首先要注意 ...
- 策略模式--Java篇
策略模式(Strategy):它定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. 下面将以商场打折为例子,说明策略模式.商场收银如何促销,用打折还是 ...