codeforces 732/D 二分】的更多相关文章

给出考试时间和考试需要准备的时间,问最早考完所有科目的时间 二分答案 NlogN 二分抄神犇的写法 感觉挺舒服的嘻嘻嘻 #include<bits/stdc++.h> using namespace std; ; int N,M,d[MAXN],w[MAXN],cnt[MAXN]; void read(int &x){ x=; register char c=getchar(); ||c>) c=getchar(); &&c<=;c=getchar()) x…
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买\(k_i\)个,每个物品在非打折日买是2块钱,在打折日买是1块钱,每天你可以赚一块钱,现在告诉你一共有m个打折日,在第\(d_i\)天第\(t_i\)种物品打折,问你你最少需要多少天可以买完你需要的物品 题解: 二分 思路是这样的 根据题目的题意,你最多打工4e5天就可以买完所有的物品,所以我们可…
题目链接:http://codeforces.com/contest/732/problem/D 题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复习a[i]天才能通过,问最早什么时候可以把所有课程都通过,如果不能输出-1. 思路:二分判断,比赛时不会check...具体见注释. #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n,m,d[N],a…
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序列中所有值都能被其中一个值整除,②且子序列范围尽可能大(r-l尽可能大). 解题思路: 对于要求1,不难发现只有min(L,R)=gcd(L,R)时才行.其中gcd是L,R范围内的最大公约数,min是L,R范围内的最小值. 对于要求2,传统思路是r-l从大到小枚举,每次确定一个(L,R)范围,进行判…
Lemmings 题目连接: http://codeforces.com/contest/163/problem/B Descriptionww.co As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at t…
题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对于第i道菜肴,他知道时间ai和bi的两个整数时刻(从宴会开始的几秒钟内) - ai为该菜端出来的时间,bi为该菜端走的时间(ai <BI).例如,如果ai = 10且bi = 11,那么第i个菜肴可在一秒钟内进食. 菜肴数量非常大,所以只要菜肴可以吃(即,在大厅里),它就无法用完. 美食家想要尝试每…
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo…
链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x 轴相切,所以圆心一定在 y = R 上,对于每一个点而言,圆要覆盖该点,那么圆心在 y = R 上一定有一段限定区间,所以只要判断这 n 个区间是否有公共区间即可.卡点:误差,太可恶了,求区间段时应该将 sqrt(R * R - d * d) 写成 sqrt(R - d) * sqrt(R + d…
Time limit4000 ms Memory limit262144 kB There are nn dormitories in Berland State University, they are numbered with integers from 11 to nn. Each dormitory consists of rooms, there are aiai rooms in ii-th dormitory. The rooms in ii-th dormitory are n…
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q queries x1, -, xq on it. For each query xi you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(al, al + 1, -, ar) = xi. 题目大意:…
A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is so…
题意:某人要考试,有n天考m个科目,然后有m个科目要考试的时间和要复习多少天才能做,问你他最早考完所有科目是什么时间. 析:二分答案,然后在判断时,直接就是倒着判,很明显后出来的优先,也就是一个栈. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include &…
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost aiEgyptian pounds.…
This is an interactive problem. In the output section below you will see the information about flushing the output. On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vičko…
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words…
题目链接:https://vjudge.net/problem/CodeForces-803B#author=0 题意: 给你一个数组,其中至少包括一个0,求每一个元素距离最近一个0的距离是多少. 样例: Input 92 1 0 3 0 0 3 2 4 Output 2 1 0 1 0 0 1 2 3 思路:把每一个0的下标都放进一个新数组中,然后枚举每一个数组pos,用二分查找pos在新数组中刚好大于等于pos的那个index,然后再和前后的index比较下取最小值,然后即得出答案. 作者的…
A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet knows the schedule: when each of the dishes will be served. For i-th of the dishes he knows two integer moments in time ai and bi (in seconds from the be…
Magazine Ad The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' i…
题意: 一个人在起点0,有n个休息点,每个点有两个数值,分别表示距离起点的距离xi,以及所获得的愉悦值bi,这个人打算每天走L距离,但实际情况不允许他这么做.定义总体失望值val = sum(sqrt(Ri - L)) / sum(bi); 现在要使得val最小(这个人必须要到达最终的节点). 析:其实这个题并不难,看好这个式子,只要变形一下,sum(sqrt(Ri - L)) - val * sum(bi) = 0,要求val最小,假设val就是最后答案那肯定满足sum(sqrt(Ri - L…
#include<bits/stdc++.h>using namespace std;const int N=1e6+6;int x[N],y[N];int sx,sy,n;char s[N];bool check(int m){    for(int i=1;i<=n-m+1;i++)    {        int tx=x[n]-x[i+m-1]+x[i-1];  //当前原来选项造成的横坐标影响        int ty=y[n]-y[i+m-1]+y[i-1];  //当前原…
思路: 暴力..我不会呀.. YY一个二分匹配嘛,然后数组开小了.GG for an hour. #include <bits/stdc++.h> using namespace std; typedef long long LL; int cy[110]; int cx[110]; int n,m; char ma[15][15]; int g[15][15]; int mma[110][110]; int dx[4]={1,-1,0,0}; int dy[4]={0,0,-1,1}; bo…
意: 求最少需要几个s1串拼接存在子串s2 (1≤|s1|≤1e4,1≤|s2|≤1e6). 思路(感谢ZQC): 每个字母的出现位置存个vector. 假设你当前已经用了A串的前x个字符,现在想要匹配一个'x',那你就在'x'的vector那里二分出第一个大于x的位置, 如果匹配不到的话,就相当于需要一个新的串. #include <bits/stdc++.h> using namespace std; typedef long long LL; vector<int>xs[30…
题目链接 Hamburgers 二分答案,贪心判断即可. #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i(0); i < (n); ++i) #define LL long long char str[1010]; LL len; LL b, c, s, nb, nc, ns, pb, pc, ps; LL money; bool judge(LL x){ LL mb = x * b; LL…
要点 可以贪心选数量最多的那三个构造 二分的话里面的check我不太会.正解是既然当前答案为\(k\)个,那每个物品最多只会出现\(k\)次,多余的丢掉,剩下的总数如果大于等于\(3k\)则true.最后输出答案时也是小小技巧吧,用\({1,1+k,1+2k}\)组成一组,因为多于\(k\)个的都删了所以这三个一定不同. #include <cstdio> #include <algorithm> #include <vector> #include <queue…
题意:给出一个n*m的矩阵,内有一些数字.当你从一个方格走到另一个方格时,按这两个方格数字的大小,有(升,平,降)三种费用.你需要在矩阵中找到边长大于2的一个矩形,使得按这个矩形顺时针行走一圈的费用,与给定费用最接近.3<=n,m<=300. 思路:O(1)计算一个矩形的费用不是什么难事,因为考虑到有前缀性质(前缀性质:[l,r] = [0,r] - [0,l-1]),只要预处理好各行各个方向行走的费用,就容易计算. 直接枚举容易得到O(n^4)的算法.难以过.这时就应当想到优化.实际上,经过…
思路: 一开始是没有办法贪心的,但是答案是可以二分的,因为窝能买k辆车的话,窝就一定能买k-1辆车:而且我最好就是拿手上钱较多的那些人去买价格便宜的车,这样肯定是能买到最多的车,而且花的少,因为对于要买的车公共钱的话够得话,那就直接公共钱付了就行,而要付出的钱是一定要付的. 所以直接二分答案. 然后人的总花费=最有钱的那些人去买最便宜的那些车的情况: #include <bits/stdc++.h> using namespace std; typedef long long LL; type…
要点 二分显然,关键在于怎么判断 题解方法:开k个队列代表每个时间有哪些电脑会挂掉,这部分O(n)预处理一下,之后扫一遍时间,每个时间点贪心选取最靠前的会挂的电脑未雨绸缪给它充电,然后看看充电以后要不要换队列,这样就把n * k的变成了n + k的 const int maxn = 2e5 + 5; int n; ll k; ll a[maxn], b[maxn], cur[maxn]; queue<int> Q[maxn]; bool ok(ll mid) { rep(i, 0, k) wh…
题意: 给一个a数组,输出有多少对相加是等于2^x的.1<=a[i]<=1e9,n<=1e5 思路: a[i]+a[j]=2^x 对于每个a[i],枚举x,然后二分查找a[j]; ps: ①:数组大的简单题,基本上就是二分这种降低复杂度: ②:对于a+b=c,三个对象都有考虑的意义: 加一发挫code-- #include<cstdio> #include<iostream> #include<queue> #include<math.h>…
题意转化:有一些区间,要求选一些连续的区间.两两区间间隔的和要求小于H.要求区间的长度和尽可能长. 二分区间长度的和,check一下就行 #include <bits/stdc++.h> using namespace std; struct node { int l,r; }; node a[]; int n,h; bool check(int mid) { ].r - a[].l; if(ans >= mid) { return true; } ; ; ; i <= n; i+…
题意: 定义F(x,p)表示的是一个数列{y},其中gcd(y,p)=1且y>x 给出x,p,k,求出F(x,p)的第k项 x,p,k<=10^6 分析: 很容易想到先二分,再做差 然后问题就变成了[1,x]内有多少个数是和p互质的 我们可以先将p质因数分解,然后用这些数组合去在[1,x]容斥就行了 long long cal(long long x) { int n=f.size(); ; ;i<(<<n);++i) { ; ; ;j<n;++j) <<j…