7E - The sum problem
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 10
50 30
0 0
Sample Output
[1,4]
[10,10] [4,8]
[6,9]
[9,11]
[30,30] // 遍历所有子列
#include<stdio.h>
int main()
{
int n, m, i,j, t, flag;
while(scanf("%d %d", &n, &m), !(n==&&m==))
{
for(i=;i<=n;i++)
{
flag=; t=;
for(j=i;j<=n;j++)
{
t+=j;
if(t==m)
{ flag=; break; }
if(t>m) break;
}
if(flag) printf("[%d,%d]\n", i, j);
}
printf("\n");
}
return ;
}
Time Limit Exceeded
// 老老实实算吧
#include<stdio.h>
#include<math.h>
int main()
{
int n, m, i,j;
while(scanf("%d %d", &n, &m), !(n==&&m==))
{
for(i=(int)sqrt(2.0*m);i>;i--) // a1*n+n*(n-1)/2=(2*a1+(n-1))*n/2=m,
{ // 又a1>=1, 则n<sqrt(2*m).
j=(*m/i-i+)/; // a1=(2*m/n-n+1)/2
if((*j+i-)*i/==m)
printf("[%d,%d]\n", j, i+j-);
}
printf("\n");
}
return ;
}
AC
7E - The sum problem的更多相关文章
- summary of k Sum problem and solutions in leetcode
I found summary of k Sum problem and solutions in leetcode on the Internet. http://www.sigmainfy.com ...
- Subset sum problem
https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...
- HDu 1001 Sum Problem 分类: ACM 2015-06-19 23:38 12人阅读 评论(0) 收藏
Sum Problem Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HD2058The sum problem
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- Maxmum subsequence sum problem
We have a lot of ways to solve the maximum subsequence sum problem, but different ways take differen ...
- HDU 2058 The sum problem(枚举)
The sum problem Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the ...
- NYOJ--927--dfs--The partial sum problem
/* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 N ...
- 动态规划法(三)子集和问题(Subset sum problem)
继续讲故事~~ 上次讲到我们的主人公丁丁,用神奇的动态规划法解决了杂货店老板的两个找零钱问题,得到了老板的肯定.之后,他就决心去大城市闯荡了,看一看外面更大的世界. 这天,丁丁刚回到家,他 ...
- HDU 2058:The sum problem(数学)
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- [java 2019-04-09] 代码生成word文档中的表格嵌套问题
public static void createContent3(Date adtStart, Date adtEnd, Map<String, Object> aMap,Map< ...
- springboot之拦截器
拦截器: package com.example.demo; import org.springframework.context.annotation.Bean; import org.spring ...
- HTML一片空白, 无法渲染: Empty tag doesn't work in some browsers
html 文件直接引入一个script, 如下 <html> <head> <script type="application/javascript" ...
- Jquery如何序列化form表单数据为JSON对象
jquery提供的serialize方法能够实现. $("#searchForm").serialize();但是,观察输出的信息,发现serialize()方法做的是将表单中的数 ...
- UI设计篇·入门篇·简单动画的实现,为布局设置动画,用XML布置布局动画
不仅仅控件可以设置动画,一个布局也可以设置动画, 当给一个布局设置了动画的时候,这个布局里所包含的控件都会依赖执行这些动画. 为布局设置动画的实现步骤: 1.新建一个动画,设置需要实现的形式 2.新建 ...
- 关于Eclipse for Python
学习Python一段时间,一直用Python的IDE进行开发,过程蛮顺利,但是,基于Visual Studio的使用经验,就希望尝试一种更友好的,更方便管理项目的IDE,分别尝试了PyCharm和Ec ...
- echarts 技巧自己的一些记录
1.不要输出 window["echarts"].init(chart) ,会卡死. let chart = document.getElementById("chart ...
- xftp无法用root账号登录问题
编辑vim /etc/ssh/sshd_config文件 把PermitRootLogin Prohibit-password 添加#注释掉 新添加:PermitRootLogin yes 更改Per ...
- 富文本编辑器 CKeditor 配置使用 (带附件)
Ckeditor下载地址:http://ckeditor.com/download 1.CKeditor的基本配置 var textval=CKEDITOR.instances.TextArea1.g ...
- webpack打包优化
https://www.cnblogs.com/vvjiang/p/9327903.html