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 ...
随机推荐
- UNIX 环境模拟工具Cygwin安装及使用图文教程
对于 UNIX 本身,也有各种称呼.IBM® 大型机用户说各种带字母 "z" 的行话,比如 IBM z/OS® 和 System z9 Virtual Machine (z/VM) ...
- Struts2自定义返回Json类型result
本来Struts2有自己的json类型的返回结果,并提供了插件,但是它有一个问题,那就是它会将所有序列化的字段都返回,如果想要制定返回Action的某一个属性,则需要在配置result时,配置参数(这 ...
- jquery ajax post请求实例
function test(){ $.ajax({ //提交数据的类型 POST GET type:"POST", //提交的网址 url:"testLogin.aspx ...
- Linux网络流量实时监控ifstat iftop命令详解(转载)
转自:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858923.html ifstat 介绍 ifstat工具是个网络接口监测工具,比较简 ...
- E20180305-hm-xa
raw adj. 生的,未加工的; 无经验的; 新近完成的; 发炎的,疼痛的; payload n. 有效载荷; (航天器.卫星的) 装备; (车辆等的) 装载货物; (炸弹.导弹的) 爆炸力;
- vue中的列表项删除操作
<script> Vue({ data: { orders: [] }, created() { $.get( { url: 'orders', dataType: 'json' }) . ...
- RabbitMQ学习之HelloWorld(1)
RabbitMQ就是一个消息代理(message broker),可以用来接收和发送消息. 消息队列有一些黑话,我们来看下: Producer : 发送message的程序 Queue : 可以用来存 ...
- 解决window.opener.obj instanceof Object会输出false的问题
在a.html页面中: window.obj = {name: "jinbang"} 在a.html页面中打开新窗口b.html页面: console.log(window.ope ...
- 《windows核心编程系列》十七谈谈dll
DLL全称dynamic linking library.即动态链接库.广泛应用与windows及其他系统中.因此对dll的深刻了解,对计算机软件开发专业人员来说非常重要. windows中所有API ...
- javascript---DOM大编程
编程练习 制作一个表格,显示班级的学生信息. 要求: 1. 鼠标移到不同行上时背景色改为色值为 #f2f2f2,移开鼠标时则恢复为原背景色 #fff 2. 点击添加按钮,能动态在最后添加一行 3. 点 ...