POJ2182:Lost Cows】的更多相关文章

浅谈线段树和树状数组:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:http://poj.org/problem?id=2182 线段树,倒着确定每一个数字.因为最后一个是唯一的,得知最后一个是什么之后倒数第二个就是唯一的了.每次询问[\(1,n\)]中还没有出现的数字第\(k\)大,直接在线段树上找.如果左儿子里可以用的数字个数大于\(k\),那么就去左儿子里面找,否则就去右儿子里找第\(k\)-左儿子可用数字个数大的数. 时间复杂度:\…
[POJ2182]Lost Cows 题面 vjudge 题解 从后往前做 每扫到一个点\(i\)以及比前面小的有\(a[i]\)个数 就是查询当前的第\(a[i]+1\)小 然后查询完将这个数删掉 两个操作可以用平衡树实现 但是我比较懒用了\(01trie\) 据说暴力也可以过 代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include &l…
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18313 Accepted: 8716 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,-,xN (…
Lost Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10544   Accepted: 6754 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'wateri…
Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25945   Accepted: 10612 Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M &…
题中给出了第 i 头牛前面有多少比它矮,如果正着分析比较难找到规律.因此,采用倒着分析的方法(最后一头牛的rank可以直接得出),对于第 i 头牛来说,它的rank值为没有被占用的rank集合中的第A[i]+1大数.所以,采用树状数组维护0-1序列(表示是否被占用)的前缀和,每次再用二分得出第K大数的下标即可. 代码如下: #include <cstdio> #include <algorithm> #include <iostream> using namespace…
Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20485   Accepted: 9719 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,..…
http://poj.org/problem?id=3621 全文翻译参自洛谷:https://www.luogu.org/problemnew/show/P2868 题目大意:一个有向图,每个点都有一个价值,每条路通过需要一定时间,求出一个回路使得价值和/时间和最大.(重复经过一个点不会额外增加价值) 按照01分数规划的套路,我们显然可以将路的边权更改为时间*枚举的答案-目的地价值,然后找一个环. 如果这个环是一个负环,那么显然答案还可以变得更大,反之则需要变小. 所以我们需要用spfa判断图…
Popular Cows Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <= 50,000) ordered pairs of the form (A, B) that tell you that cow A thinks that co…
http://poj.org/problem?id=3621 题意:有n个点m条有向边,每个点有一个点权val[i],边有边权w(i, j).找一个环使得Σ(val) / Σ(w)最大,并输出. 思路:和之前的最优比率生成树类似,还是构造成这样的式子:F(L) = Σ(val[i] * x[i]) - Σ(w[i] * x[i] * L) = Σ(d[i]) * x[i] (d[i] = val[i] - w[i] * L),要使得L越大越好. 那么当L越大的时候,F(L)就越小,如果F(L)大…