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) ...
随机推荐
- git push时报错refusing to merge unrelated histories
1. 删除本地项目中的.git目录,然后向远程仓库提交代码的时候,重新配置后再次提交.会有冲突. 解决方式: git remote add origin [//your giturl] git pul ...
- java-网络通信-索引
HTTP协议 关于HTTP协议,一篇就够了 HTTP与HTTPS的区别 HTTP Keep-Alive模式 HTTP长连接和短连接 HTTP的长连接(持久连接)和短连接 HTTP的长连接 ...
- mosquitto broker 安装服务后启动失败
一.失败原因 由于做项目用到Mqtt协议,需要安装mosquitto broker 服务,在自己本地笔记本电脑安装后直接启动服务是可以的.后来部署到服务器启动,报错缺少msvcr100.dll ,由于 ...
- 深入理解Java虚拟机读书笔记7----晚期(运行期)优化
七 晚期(运行期)优化 1 即时编译器(JIT编译器) ---当虚拟机发现某个方法或代码块的运行特别频繁时,就会把这些代码认定为“热点代码”,包括被多次调用的方法和被多次执行的循环体. ...
- 比较C#中几种常见的复制字节数组方法的效率
在日常编程过程中,我们可能经常需要Copy各种数组,一般来说有以下几种常见的方法:Array.Copy,IList<T>.Copy,BinaryReader.ReadBytes,Buffe ...
- Linux查看与挂载新磁盘
问题 把CentOS都换成了Ubuntu Server(16.04 LTS),用df -h查看磁盘占用情况,确发现之前插入的一块大容量磁盘/dev/sdb1消失了.是磁盘坏了?还是没被系统识别? 解决 ...
- 同步pod时区与node主机保持一致
一.通过环境变量设置 apiVersion: v1 kind: Pod metadata: name: pod-env-tz spec: containers: - name: ngx image: ...
- (英文版)VScode一键生成.vue模板
1. 安装vscode,官网地址 2.安装一个插件,识别vue文件 插件库中搜索Vetur,下图中的第一个,点击安装(Install) 3.新建代码片段 点击Code(代码)-Preferences( ...
- 前端笔记-jquery
一.什么是jquery 1.jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team 2.jQuery是继prototype之后又一个优秀的 ...
- base64转码,解码方法
function Base64() { // private property _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr ...