HDU 2058 The sum problem
来源:互联网 发布:单机版进销存软件地砖 编辑:程序博客网 时间:2024/04/28 06:56
水题。
题意是说给一个N,M。
在序列: 1,2,3,……,N 中找到连续数列 的和为M。
设序列长度为d.
序列最长,从1 开始。可预知的和为 d*(d-1)/2 <=m 所以 枚举d即可。
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<cmath>#define INF 0x7fffffff#define eps 1e-6#define LL long long#define CLRi for(int i=0;i<n;i++)#define CLRj for(int j=0;j<n;j++)#define CLRk for(int k=0;k<n;k++)#define debug puts("==fuck==");#define acfun std::ios::sync_with_stdio(false)#define Nmax 1001#define Mmax 1001*1001using namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m),n||m) { int l,r; int mm=m<<1; int d=(int)sqrt(mm);// cout<<d; while(d>0) { if(mm%d==0) { int tmp=(d-1)*d/2; if((m-tmp)%d==0) { l=(m-tmp)/d; r=l+d-1; printf("[%d,%d]\n",l,r); } } d--; } printf("\n"); }}
0 0
- hdu 2058 The sum problem
- hdu 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- HDU 2058 The sum problem
- hdu---2058The sum problem
- The sum problem hdu 2058
- hdu 2058 The sum problem
- HDU 2058 The Sum Problem
- HDU-2058 The sum problem
- hdu 2058 The sum problem
- HDU 2058 The sum problem
- hdu 2058 The sum problem
- The sum problem hdu 2058
- MYSQL如何计算两个日期间隔天数
- s道个歉谔谔提前去我认为而且
- mysql 查找没有插入数据的项不能使用 ***=Null 得用is null
- 信号量
- 【Android开发】之Fragment与Acitvity通信
- HDU 2058 The sum problem
- Android中使用Bitmap会出现OutOfMemory的原因(转)
- 南宁腿部吸脂手术多少钱【魔鬼的身材】
- 最简单的基于FFMPEG+SDL的音频播放器 ver2 (采用SDL2.0)
- Android性能优化
- 关于 ActionBar 的一个问题
- 加载完成一个页面后自动执行一个方法
- 营销型网站优化技巧:细节优化造就良好转化
- Sphinx武林秘籍(上)