CF Tavas and Karafs (二分)】的更多相关文章

Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almos…
C. Tavas and Karafs #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> #include <stack&g…
二分比较容易想到 #include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring>…
题意:给出一个无限长度的等差数列(递增),每次可以让从l开始的m个减少1,如果某个位置已经是0了,那么可以顺延到下一位减少1,这样的操作最多t次,问t次操作以后从l开始的最长0序列的最大右边界r是多少. 分析:由题意可以挖掘出两个条件:l~r中最大的值(因为是递增的,即r的值)必定不大于t:同时,t*m要大于或等于这一段的和.那么根据这两个条件进行二分即可. 细节:二分的右端点inf不能设置的太大,否则第一次的mid可能就会爆long long. 代码如下: #include <stdio.h>…
Tavas and Karafs Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 535C Description Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they…
535C - Tavas and Karafs 思路:对于满足条件的r,max(hl ,hl+1 ,hl+2 ,......,hr )<=t(也就是hr<=t)且∑hi<=t*m.所以通过这个条件二分找出最大的r. 二分的下界为1,上界为使得hi等于t的i(hi=t    ==>    a+(i-1)*b=t    ==>    i=(t-a)/b+1) 代码: #include<bits/stdc++.h> using namespace std; #defin…
Tavas and Karafs Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/536/problem/A Description Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kin…
题目传送门 /* 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1 二分搜索:搜索r,求出sum <= t * m的最大的r 详细解释:http://blog.csdn.net/libin56842/article/details/45082747 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> us…
题目链接: 传送门 Doctor time limit per test:1 second     memory limit per test:256 megabytes Description There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and…
%ProbS clear all;%% 数据读入与预处理 data = load('E:\network_papers\u1.base');test = load('E:\network_papers\u1.test'); R = preprocess(data.train);T = preprocess(test.test); [M,N] = size(R);[m,n] = size(T); w = resource_allocate(R,du,di); for u = 1:M    inde…
 Tavas and Nafas time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating…
[链接] 我是链接,点我呀:) [题意] 给你一个规则,让你知道第i根萝卜的高度为si = A+(i-1)*B 现在给你n个询问; 每次询问给你一个固定的起点l; 让你找一个最大的右端点r; 使得l..r这一段能够在t次"m吃操作"内被吃完. [题解] 如果l..r里面的最大值大于t了;则无解 最大值小于等于t的话. 每次可以取m个. 然后可以取t次. 也就是说 这一段里面的和<=m*t; 只要A+(i-1)*B大于1e6了就停下来 最坏情况就是A和B都为1 写个rmq+二分就好…
题意:一个等差数列,首项为a,公差为b,无限长.操作cz是区间里选择最多m个不同的非0元素减1,最多操作t次,现给出区间左端ll,在t次操作能使区间全为0的情况下,问右端最大为多少. 这么一个简单题吞了我3小时的时间.主要是没考虑全. 首先,得出ll位置的值a1,如果a1>t那么不可行. 然后分2种情况. 1.区间长度<=m,那么只要右端<=t就行,否则不行. 2.区间长度>m,区间内元素总和<=m*t,且右端<=t就行,否则不行.这个我猜到了,不过忽略了右端<=…
题目:http://codeforces.com/contest/949/problem/D 先二分一个答案,让两边都至少满足这个答案: 由于越靠中间的房间越容易满足(被检查的时间靠后),所以策略就是优先满足中间的房间,舍弃两边边缘的: 所以就由外到内推过来就可以了,用一个指针记录现在已经使用到的房间... 具体可以看这篇博客:https://www.cnblogs.com/Narh/p/9706060.html 代码如下: #include<iostream> #include<cst…
题目:http://codeforces.com/problemset/problem/1042/A 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define mid ((l+r)>>1) using namespace std; ; int n,m,a[maxn],ans,mx; bool ck(int x) { ; ;i<…
A. Tavas and Nafas time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operati…
这场比赛并没有打现场,昨天晚上做了ABCD四道题,今天做掉了E题 以前还没有过切完一场比赛的所有题呢~爽~ A. Tavas and Nafas   Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have…
C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in al…
On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v1. To get to the excursion quickly, it was decided to rent a bus, w…
1.CF 706B  Interesting drink 2.链接:http://codeforces.com/problemset/problem/706/B 3.总结:二分 题意:给出n个数,再给出q个mi,每次求n个数里有多少个数<=mi #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include&l…
CF 600B 题目大意:给定n,m,数组a(n个数),数组b(m个数),对每一个数组b中的元素,求数组a中小于等于数组该元素的个数. 解题思路:对数组a进行排序,然后对每一个元素b[i],在数组a中进行二分查找第一个大于b[i]的位置即为结果 /* CF 600B Queries about less or equal elements --- 二分查找 */ #include <cstdio> #include <algorithm> using namespace std;…
为什么Cf上所有的交互题都是$binary \; Search$... 把序列分成前后两个相等的部分,每一个都可以看成一条斜率为正负$1$的折线.我们把他们放在一起,显然,当折线的交点的横坐标为整数时有解. 我们考虑序列元素$a_{i}, a_{i + \frac{n}{2}}$,他们的差的奇偶性对于每一个$i$都是一样的,因为随着横坐标的增加,纵坐标之差要么不变,要么加减$2$. 显然如果我们询问$a_{1}, a_{1 + \frac{n}{2}}$的差是奇数,那就不可能存在解了. 我们把折…
CF 1405E Fixed Point Removal[线段树上二分]  题意: 给定长度为\(n\)的序列\(A\),每次操作可以把\(A_i = i\)(即值等于其下标)的数删掉,然后剩下的数组拼接起来,问最多能删多少个数 \(q\)次独立询问,每次把前\(x\)个数和\(后\)后\(y\)个数置为\(n+1\)之后解决上述问题 题解: 先不考虑把前\(x\)个数和后\(y\)个数置成\(n+1\)的情况 首先我们可以想到的是把所有数的值减去其下标,定义\(B_i = A_i - i\),…
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that…
三个地点构成一个三角形. 判断一下两个人能否一起到shop然后回家,如果不能: 两个人一定在三角形内部某一点分开,假设沿着直线走,可以将问题简化. 三分从电影院出来时候的角度,在对应的直线上二分出一个分离点即可. 三分角度的方法:在shop和home两个点之间找一个点p,链接p和电影院,在这个线段上面二分出分离点. 注意:精度. #include <cstdio> #include <cstring> #include <cmath> #include <algo…
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意 :有三个点,p0,p1,p2.有两个人alice,bob,他们初始位置为p0,现在 alice需要先到p2再到p1,bob是直接到p1.设计一条线路,使得他们初始一起走的路程尽可能地长(之后相遇不算).要求alice走的路程和最短路之差不超过t1,bob不超过t2. http://codeforces.com/contest/8/proble…
Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap between them. Afte…
题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是否所有关系被唯一确定.即任意一次只能有1个元素入度为0入队. #include <iostream> #include <vector> #include <algorithm> #include <string> #include <string.h&g…
GukiZ and GukiZiana 题意: 区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值 一开始以为和论文CC题一样...然后发现他带修改并且是给定了值 这样就更简单了.... 每个块维护排好序的结果 修改暴力重构+整块打标记 查询暴力查+整块二分找数量 复杂度$O(SlogS + \frac{N}{S} + S+\frac{N}{S}logS)$ woc求了一节课导数也没求出最值来又发现一开始式子列错了不管了我就开根号了..(我才不会说是因为乱搞了一下更慢了) 貌似是因为…
C. Magic Ship time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You a captain of a ship. Initially you are standing in a point (x1,y1)(x1,y1) (obviously, all positions in the sea can be desc…