Enduring Exodus CodeForces - 655C (二分)】的更多相关文章

链接 大意: n个房间, 1为占用, 0为未占用, John要将k头奶牛和自己分进k+1个空房间, 求John距最远的奶牛距离的最小值 这种简单题卡了20min.... 显然对于固定的k+1个房间, 只需要John在最接近中央的房间即可, 枚举每k个房间, 找出最接近的就行了 这样复杂度是$O(nlogk)$ 还可以直接二分答案, 复杂度$O(nlogn)$ #include <iostream> #include <algorithm> #include <cstdio&g…
题目链接: C. Enduring Exodus time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to…
C. Enduring Exodus 题目连接: http://www.codeforces.com/contest/655/problem/C Description In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he…
C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other…
题目链接: http://codeforces.com/contest/645/problem/C 题意: 给定01串,将k头牛和农夫放进, 0表示可以放进,1表示不可放进,求农夫距离其牛的最大距离的最小值. 分析: 第一遍读题没看清,直接写成dp...然后样例都不过,我开始怀疑人生怀疑自己..... 后来发现是要求中间的到两边的最大距离的最小值,而对于某个距离是否满足条件很好判断啊~~所以直接二分最大距离即可~ 代码: #include<iostream> #include<cstri…
快乐二分 用前缀和随便搞一下 #include <cstdio> using namespace std; ; int p[N]; ; inline int msum(int a, int b) { ) a = ; return (b - a - sum[b] + sum[a]); } inline bool judge(int s) { ; i <= n; i++) { ) continue; , i - ) + msum(i, i + s) >= k) return true;…
题目链接 我们将所有为0的位置的下标存起来. 然后我们枚举左端点i, 那么i+k就是右端点. 然后我们三分John的位置, 找到下标为i时的最小值. 复杂度 $ O(nlogn) $ #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <m…
枚举,三分. 首先,这$n+1$个人一定是连续的放在一起的.可以枚举每一个起点$L$,然后就是在$[L,R]$中找到一个位置$p$,使得$p4最优,因为越往两边靠,距离就越大,在中间某位置取到最优解,所以三分一下就可以了. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include…
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a.    然后求出这些学生能买自行车的最大数量,并且求当买下最大自行车数量时,总体花费私己钱的最少的钱. 我先来说以下二分搜索模板: //右值点不能取到的情况 int binary_search(vector<int>& nums,int left,int right, int targe…
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n…