Hackerrank Ad Infinitum August 2014 - Reverse Game editorial: https://www.hackerrank.com/contests/infinitum-aug14/challenges/reverse-game/editorial
Hackerrank Ad Infinitum August 2014 - Reverse Game solution:
#include <iostream> #include <cstdio> int main() { int n, k, t, cnt, a; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &k); if(k<(n-1)/2) { cnt=0, a=2; while(cnt<k) a+=2, cnt++; } else { cnt=n-1, a=1; while(cnt>k) a+=2, cnt--; } printf("%d\n", a-1); } return 0; }
No comments:
Post a Comment