Codeforces Beta Round #11-B. Jumping Jack
来源:互联网 发布:大学生有多少存款知乎 编辑:程序博客网 时间:2024/06/16 03:00
原题链接
首先对输入的x取绝对值,再用(1+a)*a/2<= x,求出最大的a, 若(1+a)*a/2 == x直接输出a,否则 e = x - (1+a)*a/2;
1.如果a + 1-e是偶数那么可以在1到a中取一个数(-e+a+1)/2往左走,输出a+1
2.如果-e+a+1是奇数,那么-e+2*a+3是偶数的话在1到a+1中取一个数(-e+2*a+3)/2往左走,输出a+2
3.若-e+2*a+3是奇数,那么-e+3*a+6一定偶数,那么输出a+3
#include <bits/stdc++.h>#define maxn 505#define MOD 1000000007using namespace std;typedef long long ll;int main(){ll a, b;scanf("%I64d", &a);a = abs(a);b = (-1 + sqrt(1+8 * a)) / 2;ll h = (1 + b) * b / 2;if(h == a){printf("%I64d\n", b);}else{ll e = a - h;e = b + 1 - e;b++;if(e % 2 == 0){printf("%I64d\n", b);}else if((e + b + 1) % 2 == 0){printf("%I64d\n", b+1);}else{printf("%I64d\n", b+2);}}return 0;}
0 0
- Codeforces Beta Round #11-B. Jumping Jack
- Codeforces Beta Round #11 B. Jumping Jack (数学)
- CodeForces 11B - Jumping Jack
- Codeforces-11B-Jumping Jack
- Codeforces 11B Jumping Jack(数学)
- CF 11B Jumping Jack
- codeforce 11B. Jumping Jack
- 11B - Jumping Jack【思维】
- cf#11-B - Jumping Jack-数学
- Codeforces Beta Round #60-B
- Codeforces Beta Round #2 B
- Codeforces Beta Round #3 B
- Codeforces Beta Round #11
- Codeforces Beta Round #28 B题
- 【dp】Codeforces Beta Round #2 B
- Codeforces Beta Round #1(A,B)
- Codeforces Beta Round #1 A B C
- Codeforces Beta Round #2--B题 (DP)
- HDU-2680 Choose the best route(SPFA)
- PAT乙级——1057. 数零壹(20)-native
- POJ - 3616 Milking Time(Dp)
- Hive简介
- day14 Set
- Codeforces Beta Round #11-B. Jumping Jack
- 理解doT.js {{## #}}
- HBase简介
- 面向过程 VS 面向对象
- TextureView 实现Camera预览
- Educational Codeforces Round 11 E. Different Subsets For All Tuples 动态规划★ ★
- 零碎知识点总结
- 关于时间复杂度
- DIP关键算法-去噪算法评价标准