题目链接如下:
这道题我没完全看懂,搜了网上题解之后也是一知半解,没能理解为什么A和B只需要0~31之间枚举即可……
(抄袭)代码如下:
#include <cstdio>
// #define debug
int pa, pb;
long long n, sp, sq, tmp, k;
int main(){
#ifdef debug
freopen("0.txt", "r", stdin);
freopen("1.txt", "w", stdout);
#endif
while(scanf("%lld %lld %lld", &n, &sp, &sq) == 3){
k = n * sq << 10;
for(int a = 0; a < 32; ++a){
for(int b = 0; b < 32; ++b){
tmp = (n - 1) * sp;
tmp = sq + ((tmp + (tmp << a)) >> b);
if(tmp < k && tmp >= n * sq){
pa = a;
pb = b;
k = tmp;
}
}
}
printf("%lld %d %d\n", k, pa, pb);
}
#ifdef debug
fclose(stdin);
fclose(stdout);
#endif
return 0;
}