51nod1615
题解:
首先,当1+2+...+n=x时,答案就是n
如果1+2+...+n不会等于x,那么找一个最小的n,让1+2+....+n>x并且(1+2+.....+n-x)%2=0
代码:
#include<iostream>
using namespace std;
int main()
{
int x,n=;
scanf("%d",&x);
x=x<?-x:x;
while()
{
int s=n*(n+)/;
if(s==x)break;
if(s>x&&(s-x)%==)break;
n++;
}
printf("%d",n);
}
51nod1615的更多相关文章
随机推荐
- Java求两个数平均值
			
如何正确的求2个数的平均值.在练习算法二分查找的时候发现的,以前没有注意到的bug 备注:数据以int类型为例 一.以前的通用写法 /** * 求a+b平均值 * @param a * @param ...
 - jQuery ajax 添加头部参数跨域
			
1.添加HTTP文件头 $.ajax({ url: "http://www.baidu.com", //contentType: "text/html; charset= ...
 - C#  实现简单的 Heap 堆(二叉堆)
			
如题,C# 实现简单的二叉堆的 Push() 和 Pop(), 如有不足欢迎指正. 另外,在C#中使用 Heap 的相似功能可以考虑使用:Priority Queues,SortedDictiona ...
 - python-ConfigParser模块--转载
			
1,函数介绍 1.1.读取配置文件 -read(filename) 直接读取ini文件内容-sections() 得到所有的section,并以列表的形式返回-options(section) 得到该 ...
 - hdu 5144 NPY and shot 物理+三分
			
NPY and shot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
 - python ros 订阅robot_pose获取机器人位置
			
#!/usr/bin/env python import rospy import tf from tf.transformations import * from std_msgs.msg impo ...
 - Could NOT find Bullet (missing: BULLET_DYNAMICS_LIBRARY BULLET_COLLISION_LIBRARY BULLET_MATH_LIBRARY BULLET_SOFTBODY_LIBRARY BULLET_INCLUDE_DIR)
			
rosdep where-defined bullet sudo apt-get install libbullet-dev
 - 刚创建的maven项目,pom.xml的第一行就报错
			
刚创建的maven项目,马上pom.xml的第一行就报错这是第一行:<project xmlns="http://maven.apache.org/POM/4.0.0" xm ...
 - STL_算法_06_遍历算法
			
◆ 常用的遍历算法: 1.1.用指定函数依次对指定范围内所有元素进行迭代访问.该函数不得修改序列中的元素 functor for_each(iteratorBegin, iteratorEnd, fu ...
 - 01_DllZZ.cpp
			
1. // DllZZ.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" ...