Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学
E. Thoroughly Bureaucratic Organization
题目连接:
http://www.codeforces.com/contest/201/problem/E
Description
Once n people simultaneously signed in to the reception at the recently opened, but already thoroughly bureaucratic organization (abbreviated TBO). As the organization is thoroughly bureaucratic, it can accept and cater for exactly one person per day. As a consequence, each of n people made an appointment on one of the next n days, and no two persons have an appointment on the same day.
However, the organization workers are very irresponsible about their job, so none of the signed in people was told the exact date of the appointment. The only way to know when people should come is to write some requests to TBO.
The request form consists of m empty lines. Into each of these lines the name of a signed in person can be written (it can be left blank as well). Writing a person's name in the same form twice is forbidden, such requests are ignored. TBO responds very quickly to written requests, but the reply format is of very poor quality — that is, the response contains the correct appointment dates for all people from the request form, but the dates are in completely random order. Responds to all requests arrive simultaneously at the end of the day (each response specifies the request that it answers).
Fortunately, you aren't among these n lucky guys. As an observer, you have the following task — given n and m, determine the minimum number of requests to submit to TBO to clearly determine the appointment date for each person.
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Each of the following t lines contains two integers n and m (1 ≤ n, m ≤ 109) — the number of people who have got an appointment at TBO and the number of empty lines in the request form, correspondingly.
Output
Print t lines, each containing an answer for the corresponding test case (in the order they are given in the input) — the minimum number of requests to submit to TBO.
Sample Input
5
4 1
4 2
7 3
1 1
42 7
Sample Output
3
2
3
0
11
Hint
题意
有n个人,每个人都有一个编号,编号都是1-n的数,且每个人的编号都不相同
你每次可以申请一个表去询问最多m个不同的人,他们的编号是哪些,但是你不知道编号和这m个人的对应关系
然后问你最少申请多少次,可以清楚知道这n个人的具体编号
题解:
每周一题 题解
div2 智商杯考试
首先这道题正面想比较麻烦。
现在我们假设你知道了MaxN(m,k),即表示每次最多提及m个问题,我询问k次,最多知道多少个答案和题目对应的这个函数。
那么我直接二分答案就好了
只要解决了MaxN(m,k),那么原题就解决了。
然后怎么去处理这个呢?
我们这样想,我们一开始有n个k位二进制数,如果在第i轮回答中提及到了第j个问题的话,那么就令第j个二进制数的第i位为1。
分析一下样例一,n = 4,k = 2,m = 2的情况:
1 0 1 0
1 1 0 0
可以看到第一个问题的序列是11,第二个问题的序列是01,第三个是10,第四个是00
由于这些二进制数都不一样,因此你能分辨出来。
只要我们最后的n个k位二进制数全部不一样,你就能分辨。
这个证明也很简单,如果有两个二进制数相同的话,那么肯定就可以交换着两个的问题的对应关系了。
那么我们怎么去询问,才能使得1的个数尽量少,且问的问题多呢?
贪心。
C(k,0)个问题,我不提及;C(k,1)个问题,我就只提及一次;C(k,2)个问题,我提及两次........C(k,r)个问题,我提及r次。
这样,最后的矩阵构造是这样的:
0 1 0 0 1 1 ... 1
0 0 1 0 1 0 ... 1
0 0 0 1 0 1 ... 1
. . . . . . ... 1
. . . . . . ... 1
0 0 0 0 0 0 ... 1
然后最后再Check一下整个矩阵的1的个数是否超过k*m,。
于是,这道题就解决了!
有人问,为什么我们只用check总共1的个数是否超过k*m,而不去check每一行的1的个数是否超过m。
其实你去check两个也是可以的,这个复杂度在本题也是可以接受的。
但是为什么呢?
证明如下:
假设我们满足总共1的个数不超过k*m,但是存在某一些位的1的个数超过了m。
那么必然存在一些位的1的个数少于m。
我们选择其中一个超过m的位X,选择其中一个少于m的位Y。
然后我们再从n个串中找到x个在X位为1,Y位为0的串,找到y个在X位中为0,Y位中为1的串。
也是显然知道x>y。
对于x个串,我们都将第X位置成0,Y位置成1,显然这x个串仍然都是各不相同的,且最多在y串中找到一个和他相同的。
因为x>y,所以肯定能够找到一个串是在y串没有与之对应的,那么我们只要变这个串就好了。
这样我们就得到了,X位置的1的总数-1,Y位置的1的总数+1了。
所以只要满足总共1的个数不要超过k*m就好了。
代码
#include <cstdio>
#define LL long long
using namespace std;
int T, n, m;
inline bool ok(LL k){
    LL t = k * m, cnt = 1, tmp = 1;
	for (LL i = 1; i <= k; i++){
		tmp = tmp * (k - i + 1) / i;
		if (i <= t / tmp) t -= i * tmp, cnt += tmp;
		else{cnt += t / i; break;}
	}
	return cnt >= n;
}
inline LL calc(){
	LL l = 0, r = n;
	while (l < r){
		LL mid = (l + r) >> 1;
		if (ok(mid)) r = mid; else l = mid + 1;
	}
	return r;
}
int main(){
	for (scanf("%d", &T); T--;){
		scanf("%d%d", &n, &m);
		if (m + m > n) m = n / 2;
		printf("%I64d\n", calc());
	}
}Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学的更多相关文章
- Codeforces Round #426 (Div. 1) A.The Meaningless Game (二分+数学)
		题目链接: http://codeforces.com/problemset/problem/833/A 题意: 给你 \(a\) 和 \(b\),两个人初始化为 \(1\).两个人其中一方乘以 \( ... 
- Codeforces Round #275 (Div. 2)  B. Friends and Presents 二分+数学
		8493833 2014-10-31 08:41:26 njczy2010 B - Friends and Presents G ... 
- Codeforces Round #365 (Div. 2)  C - Chris and Road 二分找切点
		// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ... 
- Codeforces Round #127 (Div. 1) D. Brand New Problem 暴力dp
		D. Brand New Problem 题目连接: http://www.codeforces.com/contest/201/problem/D Description A widely know ... 
- Codeforces Round #127 (Div. 1) C. Fragile Bridges dp
		C. Fragile Bridges 题目连接: http://codeforces.com/contest/201/problem/C Description You are playing a v ... 
- Codeforces Round #127 (Div. 1) B. Guess That Car! 扫描线
		B. Guess That Car! 题目连接: http://codeforces.com/contest/201/problem/B Description A widely known amon ... 
- Codeforces Round #127 (Div. 1) A. Clear Symmetry 打表
		A. Clear Symmetry 题目连接: http://codeforces.com/contest/201/problem/A Description Consider some square ... 
- Codeforces Round #127 (Div. 2)
		A. LLPS 长度最大10,暴力枚举即可. B. Brand New Easy Problem 枚举\(n\)的全排列,按题意求最小的\(x\),即逆序对个数. C. Clear Symmetry ... 
- Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学
		D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ... 
随机推荐
- Caffe学习笔记3
			Caffe学习笔记3 本文为原创作品,未经本人同意,禁止转载,禁止用于商业用途!本人对博客使用拥有最终解释权 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和h ... 
- python实战===国内很简单实用的一些开源的api以及开源项目
			原创 2017年03月25日 15:40:59 标签: api / 开源项目 / app / 免费接口 声明 以下所有 API 均由产品公司自身提供,本人皆从网络获取.获取与共享之行为或有侵犯产品 ... 
- 2015多校第6场 HDU 5354 Bipartite Graph CDQ,并查集
			题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5354 题意:求删去每个点后图是否存在奇环(n,m<=1e5) 解法:很经典的套路,和这题一样:h ... 
- C高级 框架开发中红黑树结构
			引言 -- 红黑树历史 红黑树是数据结构学习中一道卡. 底层库容器中必不可少的算法. 历经各种实战运用,性能有保障. 同样红黑树不好理解, 就算理解了, 代码也不好写. 就算写了, 工程库也难构建. ... 
- VM虚拟机,Linux系统安装tools过程遇到 what is the location of the “ifconfig” program
			安装步骤: 复制到/mnt 解压文件 tar -zxvf VMwareTools-10.1.6-5214329.tar.gz 进入减压文件夹后安装 ./vmware-install.pl ... 一直 ... 
- 浅谈Javascript设计模式
			什么是模式 模式是一种可复用的解决方案,可用于解决软件设计中遇到的常见问题. 也就是说用来解决常见问题的可复用的解决方案. 常见的js设计模式 Constructor(构造器)模式 Construct ... 
- php设计模式四 ---- 原型模式
			1.简介 用于创建重复的对象,同时又能保证性能.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式 意图:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 主要解决:在运 ... 
- 23:django 信号(signal)
			django包含了一个“信号分配器”使得当一些动作在框架的其他地方发生的时候,解耦的应用可以得到提醒.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者,这是特别有用的设计因为有些 ... 
- 面试题之堆栈队列系列一:设计包含min函数的栈
			编译环境 本系列文章所提供的算法均在以下环境下编译通过. [算法编译环境]Federa 8,linux 2.6.35.6-45.fc14.i686 [处理器] Intel(R) Core(TM)2 Q ... 
- centos7 安装rlwrap
			https://blog.csdn.net/zhjmozhi/article/details/78347216 
