UVa 714 Copying Books - 二分答案
2017-04-03 11:58
309 查看
![](https://images2015.cnblogs.com/blog/989955/201704/989955-20170403115351597-1987783037.png)
求使最大值最小,可以想到二分答案。
然后再根据题目意思乱搞一下,按要求输出斜杠(这道题觉得就这一个地方难)。
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 = 1; while(!isdigit((x = getchar())) && x != '-'); if(x == '-'){ x = getchar(); aFlag = -1; } for(u = x - '0'; isdigit((x = getchar())); u = (u << 1) + (u << 3) + x - '0'); ungetc(x, stdin); u *= aFlag; } int T; int n, a, b; template<typename T> T pow(T a, int pos) { if(pos == 0) return 1; if(pos == 1) return a; T temp = pow(a, pos / 2); if(pos & 1) 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 == 0) return 1; if(top == 1 && bottom == (1 << dep)) return pow((long long)3, dep); int mid = 1 << (dep - 1); if(bottom <= mid) return 2 * dfs(dep - 1, top, bottom); if(top > mid) return dfs(dep - 1, top - mid, bottom - mid); return 2 * dfs(dep - 1, top, mid) + dfs(dep - 1, 1, bottom - mid); } inline void solve() { long long res = dfs(n, a, b); printf(AUTO"\n", res); } int main() { readInteger(T); for(int kase = 1; kase <= T; kase++) { init(); printf("Case %d: ", kase); solve(); } return 0; }
相关文章推荐
- 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx
- 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx
- 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx
- 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx
- UVa 714 - Copying Books 二分答案
- UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)
- UVa 714 Copying Books(二分)
- UVA ~ 714 ~ Copying Books(二分+最大值最小化)
- uva 714 - Copying Books(贪心 最大值最小化 二分)
- UVa 714 抄书 二分答案
- UVa 714 (二分) Copying Books
- UVA 714 Copying Books 抄书 (二分)
- uva 714 - Copying Books(二分+贪心)
- UVA 714 Copying Books 二分
- UVa 714 Copying Books——二分最大值最小化
- UVa 714 Copying Books (最大值尽量小_二分+贪心)
- uva 714 Copying Books (二分)
- UVa 714 Copying Books 二分 + 贪心 (最大值最小化问题)
- UVA 714 Copying Books(二分+贪心)
- UVA 714 Copying Books (二分)