UVa 714 Copying Books - 二分答案

时间:2023-03-10 04:12:47
UVa 714 Copying Books - 二分答案

UVa 714 Copying Books - 二分答案


  求使最大值最小,可以想到二分答案。

  然后再根据题目意思乱搞一下,按要求输出斜杠(这道题觉得就这一个地方难)。

Code

 /**
* UVa
* Problem#12627
* Accepted
* Time:0ms
*/
#include<iostream>
#include<cstdio>
#include<cctype>
#include<ctime>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<stack>
#ifndef WIN32
#define AUTO "%lld"
#else
#define AUTO "%I64d"
#endif
using namespace std;
typedef bool boolean;
#define inf 0xfffffff
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
template<typename T>
inline void readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-');
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
} int T;
int n, a, b; template<typename T>
T pow(T a, int pos) {
if(pos == ) return ;
if(pos == ) return a;
T temp = pow(a, pos / );
if(pos & ) return temp * temp * a;
return temp * temp;
} inline void init() {
readInteger(n);
readInteger(a);
readInteger(b);
} long long dfs(int dep, int top, int bottom) {
if(dep == ) return ;
if(top == && bottom == ( << dep)) return pow((long long), dep);
int mid = << (dep - );
if(bottom <= mid) return * dfs(dep - , top, bottom);
if(top > mid) return dfs(dep - , top - mid, bottom - mid);
return * dfs(dep - , top, mid) + dfs(dep - , , bottom - mid);
} inline void solve() {
long long res = dfs(n, a, b);
printf(AUTO"\n", res);
} int main() {
readInteger(T);
for(int kase = ; kase <= T; kase++) {
init();
printf("Case %d: ", kase);
solve();
}
return ;
}