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 ;
}
UVa 714 Copying Books - 二分答案的更多相关文章
- UVA 714 Copying Books 二分
题目链接: 题目 Copying Books Time limit: 3.000 seconds 问题描述 Before the invention of book-printing, it was ...
- uva 714 Copying Books(二分法求最大值最小化)
题目连接:714 - Copying Books 题目大意:将一个个数为n的序列分割成m份,要求这m份中的每份中值(该份中的元素和)最大值最小, 输出切割方式,有多种情况输出使得越前面越小的情况. 解 ...
- UVa 714 Copying Books(二分)
题目链接: 传送门 Copying Books Time Limit: 3000MS Memory Limit: 32768 KB Description Before the inventi ...
- UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)
Copying Books Before the invention of book-printing, it was very hard to make a copy of a book. A ...
- 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx
Before the invention of book-printing, it was very hard to make a copy of a book. All the contents h ...
- uva 714 - Copying Books(贪心 最大值最小化 二分)
题目描写叙述开头一大堆屁话,我还细致看了半天..事实上就最后2句管用.意思就是给出n本书然后要分成k份,每份总页数的最大值要最小.问你分配方案,假设最小值同样情况下有多种分配方案,输出前面份数小的,就 ...
- UVa 714 Copying books 贪心+二分 最大值最小化
题目大意: 要抄N本书,编号为1,2,3...N, 每本书有1<=x<=10000000页, 把这些书分配给K个抄写员,要求分配给某个抄写员的那些书的编号必须是连续的.每个抄写员的速度是相 ...
- UVA 714 Copying Books 抄书 (二分)
题意:把一个包含m个正整数的序列划分成k个非空的连续子序列.使得所有连续子序列的序列和Si的最大值尽量小. 二分,每次判断一下当前的值是否满足条件,然后修改区间.注意初始区间的范围,L应该为所有正整数 ...
- UVA - 714 Copying Books (抄书)(二分+贪心)
题意:把一个包含m个正整数的序列划分成k个(1<=k<=m<=500)非空的连续子序列,使得每个正整数恰好属于一个序列(所有的序列不重叠,且每个正整数都要有所属序列).设第i个序列的 ...
随机推荐
- Centralized Cache Management in HDFS
Overview(概述) Centralized cache management in HDFS is an explicit caching mechanism that allows users ...
- python面向对象高级:@property
@property 把方法『变成』了属性,广泛应用在类的定义中,可以让调用者写出简短的代码,同时保证对参数进行必要的检查,这样,程序运行时就减少了出错的可能性. 最大的作用就是既能检查参数,又可以用类 ...
- C# 枚举 小总结
枚举 枚举类型声明为一组相关的符号常数定义了一个类型名称. 枚举类型为定义一组可以赋给变量的命名整数常量提供了一种有效的方法.例如:假设你必须定义一个变量,该变量的值表示一周中的一天.该变量只能存储七 ...
- 自动布局又出问题-HPPGCTableViewCell
[self.firstComment mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(sel ...
- Django - 用户认证、用户组、用户权限
https://www.cnblogs.com/ccorz/p/6358074.html auth模块是Django提供的标准权限管理系统,可以提供用户身份认证, 用户组和权限管理. auth可以和a ...
- VMware Pro v14.0.0 官方版本及激活密钥
热门虚拟机软件VMware Workstation Pro 14.0 全新版本发布,此次更新了诸多客户机操作系统版本,另外完全兼容Wind10创建者更新支持.12.0之后属于大型更新,专门为Win10 ...
- PAT 1029 Median[求中位数][难]
1029 Median(25 分) Given an increasing sequence S of N integers, the median is the number at the midd ...
- html07
1.复习js的外部对象,DOM,BOMBOM window -location -Location对象 : href reload() -history -History :back() forwar ...
- cordova+Android Studio 1.0+ionic+win7(转)
转自http://blog.csdn.net/fuyunww/article/details/42216125 目录(?)[-] 在项目目录下执行 a创建工程 b添加平台支持 c添加插件在Androi ...
- sqlserver 获得行号作为唯一id
当sqlserver创建的view没有唯一的标识字段里,entity framework codefirst配置会出现错误,因为取其行号作为唯一标识列 CREATE VIEW [SafeWatch]. ...