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 ...
随机推荐
- 强化基础 Action ac = (System.Action)delegate() { Console.WriteLine("123456"); }; ac(); 委托间 也是 可以相互转换的
委托间 也是 可以相互转换的
- Android开源git40个App源代码
(JamsMusicPlayer)非常棒的音乐播放器(new) (F8)日程安排的软件 (Conversations)基于XMPP的应用 (Bitocle)能够在手机上查看自己github ...
- 搭建基于Jenkins的CI服务器
安装Jenkins和创建任务这些操作网上一搜一大把,这里就没必要写了,直接就开始编译.单元测试,覆盖,git提交触发构建,构建失败发送给提交人邮件. 因为项目比较复杂,为了懒省事我直接在CI服务器上安 ...
- Graphics and Animation in iOS
using System;using UIKit;using CoreGraphics;using Foundation; namespace GraphicsAnimation{ public c ...
- WPF popup控件的使用
<Window x:Class="WPFPopup.RuntimePopup" xmlns="http://schemas.microsoft.com/wi ...
- iOS开发教程:Storyboard全解析-第一部分
本文转载至http://blog.csdn.net/chang6520/article/details/7945845 感谢原文作者分享 故事版(Storyboard)是一个能够节省你很多设计 ...
- EasyDarwin接入ffmpeg实现264转图片快照功能
本文转自:http://blog.csdn.net/cai6811376/article/details/51774467 EasyDarwin一直坚持开源精神,所以我们着手把EasyDarwin中使 ...
- c#4.5新语法--自动属性和隐式类型
1.自动属性 自动属性是c#中属性定义的两种形式的一种:传统属性定义.自动属性. 1.1 传统属性定义 private int _age; public int ...
- 项目中一个普通的Java类如何获取service接口(一)
在普通的Java类中获取service接口目的是调用接口中的方法,实现数据的持久化等操作: Java类中的获取service接口方法: IfaceDetectService faceDetectSer ...
- memset 导致的段错误(segmentation fault)
在调试Minixml库时,定义了一个结构体: struct ssid_info_s{ std::string wl_ssid_name; std::string wl_ssid_mac; std::s ...