hdu2058(数学题,有点坑)
来源:互联网 发布:矩阵计算中文第四版pdf 编辑:程序博客网 时间:2024/06/03 18:19
The sum problem
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 24916 Accepted Submission(s): 7449
Problem Description
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.
Input
Input contains multiple test cases. each case contains two integers N, M( 1 <= N, M <= 1000000000).input ends with N = M = 0.
Output
For 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 Input
20 1050 300 0
Sample Output
[1,4][10,10][4,8][6,9][9,11][30,30]
Author
8600
Source
校庆杯Warm Up
等差数列求和公式,但是一直超时。。。因为没有剪枝,其实sqrt(m*2)就够了,我一直是从m开始 虽然没错但就是超时,数学题还是要多练啊!
#include <iostream> #include <cmath>#include <iomanip>#include <string>using namespace std;int main(void){int n,m;while(cin>>n>>m && n||m){for(int i=sqrt(2*m);i>=1;i--){int a=(m-((i-1)*i)/2)/i;if(m==a*i+(i*(i-1))/2&&a>0)cout<<'['<<a<<','<<a+i-1<<']'<<endl;}cout<<endl;}return 0;}
0 0
- hdu2058(数学题,有点坑)
- HDU2058 水题 数学题 几个数之和
- HDU2058
- hdu2058
- HDU2058
- hdu2058
- hdu2058
- hdu2058
- hdu2058 The sum problem(C语言)
- HDU 1058 简单数学题,有点思维
- poj1152 数学题(进制位)
- hdu 2178 (数学题)
- poj 1019(数学题)
- 糖果传递 (数学题)
- cf(cards)数学题
- hdu 2832(数学题)
- 数学题(1)
- HDU5100 Chessboard(数学题)
- 静态代理
- 多线程之线程池的应用
- LeetCode 39. Combination Sum
- 【hadoop集群搭建和代码调试】总结17/2/18
- elasticsearch索引管理
- hdu2058(数学题,有点坑)
- SQL Server2016 新功能之SQL安装篇
- 白话经典算法系列之一 冒泡排序的三种实现
- 栈,堆,队列
- 沉浸式状态栏
- python绘图 初识Python绘图
- 工具类-ActivityStack
- mymps蚂蚁分类系统5.8E UTF8 开源版 新功能详细介绍
- zookeeper原理(转)