HDOJ-2058
The sum problem
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 21744 Accepted Submission(s): 6391Problem DescriptionGiven 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.InputInput contains multiple test cases. each case contains two integers N, M( 1 <= N, M <= 1000000000).input ends with N = M = 0.OutputFor each test case, print all the possible sub-sequence that its sum is M.The format is show in the sample below.print a blank line after each test case.Sample Input20 1050 300 0Sample Output[1,4][10,10][4,8][6,9][9,11][30,30]
本题题意:
输入两个数n,m,n代表数列为从1~n的等比为1的等比数列,求其中连续哪几个数的和为m,并输出。
运用等差数列的求和公式就能很好的解决这个问题。下面重申一下等差数列的求和公式:
附AC代码:
#include<iostream>
#include<cstdio>
#include<cmath>//包含开根函数sqrt() using namespace std; int main(){
int n,m;
while(~scanf("%d %d",&n,&m)&&m||n){
for(int i=sqrt(*m);i>=;i--){//1连加到sqrt(2*m) > m
int a=(m-(i*(i-))/)/i;//等差求和公式推出
if(m==a*i+(i*(i-))/)
printf("[%d,%d]\n",a,a+i-);
}
printf("\n");//注意每组数据空一行
}
return ;
}
HDOJ-2058的更多相关文章
- HDOJ 2058 The sum problem
Problem Description Given a sequence 1,2,3,--N, your job is to calculate all the possible sub-sequen ...
- hdoj:2058
#include <iostream> #include <cmath> #include <vector> using namespace std; stru ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- bzoj 2058+2059+2060 Usaco2010 Nov
三道金组比较容易的题目.. 2058 首先交换次数就是逆序对数,因为只能交换相邻的两数 先对原序列找逆序对数 用树状数组nlogn求出 然后O(n)依次求出其循环序列的逆序对数 比如 3 5 4 2 ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
- 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ
前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...
随机推荐
- idea自动注入和自动编译
---恢复内容开始--- 自动编译也就是时时编译,当我们写错代码的时候,idea能够马上报错,这个是不错的功能. 安装操作看下图: 下面这个功能的作用就是,如果你不修改的话,你的项目可以正常运行,但是 ...
- Numpy数组计算
NumPy是高性能科学计算和数据分析的基础包.它是pandas等其他各种工具的基础. NumPy的主要功能 ndarray,一个多维数组结构,高效且节省空间 无需循环对整组数据进行快速运算的数学函数 ...
- IOS AFNETWORKING POST
IOS AFNETWORKING POST 请求 #pragma mark post 请求 // 获取 url 路劲,不带参数 NSString *requestUrl = [[url compone ...
- UVA 11888 - Abnormal 89's(Manachar)
UVA 11888 - Abnormal 89's option=com_onlinejudge&Itemid=8&page=show_problem&category=524 ...
- 九度OJ 1086:最小花费 (DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3960 解决:819 题目描述: 在某条线路上有N个火车站,有三种距离的路程,L1,L2,L3,对应的价格为C1,C2,C3.其对应关系如下 ...
- finding friends with mapreduce
http://stevekrenzel.com/finding-friends-with-mapreduce
- java之折半查找
//功能:二分查找import java.util.*; public class Demo1 { public static void main(String[] args) { int arr[] ...
- 新版的Spring4X怎样下载
点击下载 <a href="http://download.csdn.net/detail/zhaoqingkaitt/7733719">点击免费下载</a> ...
- No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386).错误解决方法
targets ->build setting 下的 Build Active Architecture Only 设置 NO 就可以.
- 8.JS数据类型
① 数据类型:字符串,数字,布尔,数组,对象,Null,Undefined ② JavaScript拥有动态类型.这意味着相同的变量可用作不同的类型: 实例 var x: //x为undefine ...