题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然后枚举k,每次用二分找到小于k∗aj而且最大的ai,维护答案,过程中加了一些剪枝. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn =…
题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最大值非常明显a[i]越接近a[j]的倍数则余数越大 ,因此我们将全部的元素从大到小排序 : 然后枚举a[j]的倍数 ,二分查找小于a[i]倍数的最大值,然后更新余数的最大值. 代码例如以下: #include <iostream> #include <cstdio> #include…
E - E CodeForces - 1100E 一个n个节点的有向图,节点标号从1到n,存在m条单向边.每条单向边有一个权值,代表翻转其方向所需的代价.求使图变成无环图,其中翻转的最大边权值最小的方案,以及该方案翻转的最大的边权. Input 单组输入,第一行包含两个整数n和m(2≤n≤100 000,1≤m≤100 000) 接下来m行,每行3个整数,u_i ,v_i ,w_i (1<= u_i , v_i <= n, 1<= w_i <= 10^9),表示u到v有一条权值为w…
B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divided by…
意甲冠军: a序列n(2*10^5)数字  问道a[i]>=a[j]如果是  a[i]%a[j]最大值是多少 思路: 感觉是一道挺乱来的题-- 我们能够将ans表示为a[i]-k*a[j]  这样我们枚举k仅仅要知道比k*a[j]大可是不到(k+1)*a[j]的值就好了  考虑到a[i]仅仅要10^6大  因此能够用一个last数组记录小于等于i的数组中的数字  因此仅仅要拿出last[(k+1)*a[j]-1]就好 暴力可能会T有一些能够让程序加速的方法  输入开挂  a数字去重  从大到小枚…
题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优的值,用它模x更新.一旦最优值是最后一个元素,那么更新完后break;对数组排序完后对每个元素进行如上操作.(跳过1),复杂度为n/2+n/3+......=n(1/2+1/3+......)=nlogn.不过超时了.因为如果数组中全是2,最后一个为99999,复杂度为n/2+n/2+......=…
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of *a**i* divi…
UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了那句话:基础不牢,地动山摇. 记录一下自己BS的常见错误: 1.需要传入的参数是,搜索的区间[l,r]和搜索的目标值t; 2.一般被搜索的对象以全局变量的身份出现,故不需要传参进去; 3.退出循环的条件是l < r 注意这里可没有等号; 4.若t在mid左边或等于mid,要把右坐标r移动到m的位置,…
题目链接: B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divi…
In the lattice points of the coordinate line there are n radio stations, the i-th of which is described by three integers: xi — the coordinate of the i-th station on the line, ri — the broadcasting range of the i-th station, fi — the broadcasting fre…
题目链接: http://codeforces.com/problemset/problem/645/D 题意: 给定n个机器人的m个能力大小关系,问你至少要前几个大小关系就可以得到所有机器人的能力顺序. 分析: 拓扑+二分. 注意最终的顺序不能缺点,先把度为0的点入队,如果度为0的点的个数大于1,则说明至少有两个点的能力大小不确定,无法继续. 代码: #include<bits/stdc++.h> using namespace std; const int maxn = 100005; v…
You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of is maximized. Chosen sequence can be empty.…
Maximum Value Time limit 1000 ms Memory limit 262144 kB You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj. Input The first line contains in…
很有趣的一道题,题解戳这. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; + ; int a[maxn], f[maxm]; int main() { int n; scanf("%d", &n); ; i < n; i++) scanf("%d"…
题目链接: http://www.codeforces.com/contest/655/problem/D 题意: 题目是要求前k个场次就能确定唯一的拓扑序,求满足条件的最小k. 题解: 二分k的取值,做拓扑排序的时候只要每次只有一个元素没有前驱就可以唯一了. #include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<queue> #includ…
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was…
C - Preparing for the Contest Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 377B Description Soon there will be held the world's largest programming contest, but the testing system sti…
原题传送门 E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequen…
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109. I…
题目链接:http://codeforces.com/contest/799/problem/C 题意:要求造2座fountains,可以用钻石,也可以用硬币来造,但是能用的钻石有限,硬币也有限,问能造出最大的美丽值为多少. 题解:显然如果两个fountains分别用钻石和硬币来造的话就直接取两种类型里满足条件的最大值即可. 如果选的是同类的话,先按照数量来排序,然后那一个数量为基准二分下个可行的数量,然后还需要一个 数组来存小于等于某个数量的最大美丽值. #include <iostream>…
题目描述: Match Points time limit per test 2 seconds memory limit per test 256 mega bytes input standard input output standard output You are given a set of points x1, , ..., *x**n* Two points iand jcan be matched with each other if the following conditi…
题目链接:https://codeforces.com/contest/1156/problem/C 题意:给出n个数和整形数z,定义一对数为差>=z的数,且每个数最多和一个数组成对,求最多有多少对. 思路:先按升序排序,在区间[0,n/2]二分答案即可,判断m是否满足条件利用贪心思想,即看前x个数和后x个数是否能对应组成对. AC代码: #include<cstdio> #include<algorithm> using namespace std; ]; bool jud…
原题链接:http://codeforces.com/contest/830/problem/A 题意:在一条数轴上分别有n个人和k把钥匙(n<=k),以及一个目的地,每个人要各自拿到一个钥匙后到达目的地.每个人的移动速度都是1, 问所有人都到达目的地的最短时间. 思路:转化一下题意,就是求耗时最长的人所用的最短时间. 我们可以二分答案x,然后对排序后的人以及钥匙进行枚举,进行从左至右搭配. 这里check函数中返回false的条件是从左至右所有人都能在x的时间内到达目的地,而计算这些人到达目的…
原题链接 2300分 大意 俄罗斯套娃,每个有内容半径in和外围半径out in_i<out_i 如果 in_i >= out_j ,那么j可以放在i内 定义残留空间 = 一列嵌套的套娃 未使用的半径和 ,如 {1,2},{2,5},{7,9},未使用的白净和为(1-0)+(2-2)+(7-5) = 3 有效残留空间,如果 一列嵌套的套娃,还能从给出的套娃中选择一个加入这一列,那么原本的残留空间为无效值.如给{1,2},{2,3},{2,5},{7,9},只选择{1,2},{7,9}是无效的嵌…
原题: ZOJ 3676  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3676 题意:给每个朋友一瓶可乐,可乐有普通和高级两种,每个朋友只能喝一瓶可乐,喝普通可乐的朋友会给你P个瓶盖,喝高级可乐的朋友会给你Q个瓶盖.问最多能得到多少个瓶盖.瓶盖可以借. 解法:因为瓶盖可以借任意多个,所以按Q-P排序即可,二分临界点Q-P=0的点,即Q-P<m的让他和普通可乐,Q-P>m的喝高级可乐,Q-P=m的无所谓喝什么. 代码…
题目链接:http://codeforces.com/contest/332/problem/B 题意:在一个序列中,在所有长度为k的区间里找出两个不重叠的最大和,输出这两个最大和所对应的开头的位置a和b. 一开始没有想到用dp来做,于是有了以下的错误思路(读者可以忽略):声明一个结构体,包括head(保存起始点).tail(保存结束点)还有sum(保存长度为k的区间的和).计算出整个序列所有k个小区间的和sum,按sum从大到小排序(隐含的弊端:排序会导致区间与区间之间起始点和结束点的位置很不…
Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1839 Description Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. The vertex numbered with…
题目链接: D. Delivery Bears time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees…
A - Luggage DistributionTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87493#problem/A Description All provident tourists know about low-cost airlines. Those who used them at least once also know th…
题目链接 将给出的已经有了的排序, 在前面加上0, 后面加上1e9+1. 然后对相邻的两项判断. 如果相邻两项之间的数的和小于m, 那么全都选上, m减去相应的值. 如果大于m, 那么二分判断最多能选多少个. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <complex>…