本文主要是介绍679 - Dropping Balls (UVA),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接如下:
Online Judge
我的方法不是很直观....更简洁的方式在这里:UVa 679 - Dropping Balls_uva dropping balls-CSDN博客
我的代码如下:
#include <cstdio>
#include <cmath>
// #define debugint l, d, k, loc, len;int main(){#ifdef debugfreopen("0.txt", "r", stdin);freopen("1.txt", "w", stdout);#endifscanf("%d", &l);while (l--){scanf("%d %d", &d, &k);loc = pow(2, d - 1);len = loc / 2;while (k){if (k % 2 == 0){loc += len;}if (k < 2){break;}k = (k + 1) / 2;len /= 2;}printf("%d\n", loc);}scanf("%d", &l);#ifdef debugfclose(stdin);fclose(stdout);#endifreturn 0;
}
这篇关于679 - Dropping Balls (UVA)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!