codeforce 11B 思维题
来源:互联网 发布:网络前沿技术有哪些 编辑:程序博客网 时间:2024/06/07 19:56
http://codeforces.com/problemset/problem/11/B
B. Jumping Jack
time limit per test
1 secondmemory limit per test
64 megabytesinput
standard inputoutput
standard outputJack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Sample test(s)
input
2
output
3
input
6
output
3
input
0
output
0
#include <iostream>#include<cstdio>using namespace std;int main(){ int x,n,s,w; while(~scanf("%d",&x)) { n=0; x=x>=0?x:-x; while(1) { s=n*(n+1)/2; if(x==s) break; if(s>x) { int c=s-x; if(c%2==0) break; } n++; } cout<<n<<endl; } return 0;}
0 0
- codeforce 11B 思维题
- codeforce 10B 思维题
- codeforce 432B - Football Kit 思维题
- codeforce 4B(思维水题)
- codeforce 558B Amr and The Large Array 思维题
- codeforce-501【B思维&&map】【C思维&&树】
- Codeforce 839 -- B Game of the Rows 【思维 + 贪心】
- Codeforce-839B Game of the Rows 思维
- codeforce-231B--- Magic, Wizardry and Wonders (思维+构造)
- codeforce 11 11 A B
- codeforce 11B. Jumping Jack
- codeforce 168#div2 B题
- codeforce 416/B 动态规划简单题
- CODEFORCE 246 Div.2 B题
- B. Permutation----思维题
- Codeforce 894B Ralph And His Magic Field (思维+快速幂)
- codeforce 9C 找规律的思维题
- codeforce 796 c Bank Hacking (思维题,分类讨论)
- 数据结构实验之大数相乘
- C++类运算符重载实验
- dffwgrfrfrefnre
- notepad中文复制乱码的问题
- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
- codeforce 11B 思维题
- 数据库的建立——物资管理系统
- 关于typedef的用法总结
- javaweb 手动配HTTP
- 黑马程序员--IO流之字符流
- C++类和对象的继承和派生
- HOG特征描述
- <MFC笔记> 四种线程同步(或互斥)方式小结
- Notes On <Practical ASP.NET Web API> - 01