[Luogu] 区间统计Tallest Cow】的更多相关文章

https://www.luogu.org/problemnew/show/P2879 差分 | 线段树 #include <iostream> #include <cstdio> #include <algorithm> using namespace std; ; #define gc getchar() struct Node {int l, r;}A[N]; int n, my, Maxh, R; int H[N]; inline int read() { ;…
P2879 [USACO07JAN]区间统计Tallest Cow 差分 对于每个限制$(l,r)$,我们建立一个差分数组$a[i]$ 使$a[l+1]--,a[r]++$,表示$(l,r)$区间内的数至少比$l,r$小$1$ 最后统计下前缀和,顺便把最大高度加上去. 记得判重. (逃一节晚自习真chiji) 不写了,放风时间到了. #include<iostream> #include<cstring> #include<cstdio> #include<alg…
To 洛谷.2879 区间统计 题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of the tallest cow along with th…
题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of the tallest cow along with the index I of tha…
题目链接: https://www.luogu.org/problemnew/show/P2879 思路: 先不管最大高度,我们读入一对x,y.说明,x+1~y-1之间牛的身高都小于x,y. 然后不妨将这个区间打个标记-1.所有操作后,可知最高的那个牛它的标记一定是0,并且标记数量与身高排名正相关,于是再将所有奶牛的标记数加上最高身高h就是可能的最大身高. 因为之前的操作保证标记的数量是按着身高排名来的,加上最大身高当然是最大可能身高. 然后我们是要将x+1~y-1打标记,根据差分数组的思维,就…
传送门 题目大意: n头牛,其中最高身高为h,给出r对关系(x,y) 表示x能看到y,当且仅当y>=x并且x和y中间的牛都比 他们矮的时候,求每头牛的最高身高. 题解:贪心+差分 将每头牛一开始都设为最高高度. 每一对关系(x,y),我们将[x+1,y-1]这个区间的身高变为 min(x,y)-1.这样是不对了.因为要维护[x+1,y-1]这个区间里 各个元素的大小关系,所以要将[x+1,y-1]的元素身高都减1. 一开始我是用线段树做的,后来发现题解用的差分. 没有询问的区间修改,差分做就好了…
前缀和 sum[i]表示前i个数的和 每次读入a[i]的时候 sum[i] = sum[i - 1] + a[i]; 查询l ~ r区间的和: sum[r] - sum[l - 1] 差分 即前缀和的修改操作 我们定义pre[i]表示前i个数需要改变的值 则对一个区间l ~ r + k的操作是 pre[r] + k; pre[l - 1] - k; 则多算的1 ~ l - 1部分就抵消,等价与l ~ r + k; 本题中同一关系可能给出多次,需用map或hash判重 #include<iostr…
FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of the tallest cow along with the index I of that cow…
http://www.lydsy.com/JudgeOnline/problem.php?id=1635 差分序列是个好东西啊....很多地方都用了啊,,, 线性的进行区间操作orz 有题可知 h[a+1]~a[b-1]都是比h[a]和h[b]小,那么最佳方案就是将次区间的所有高度-1,那么我们就将整个区间-1 也就是sum[a+1]--, sum[b]++ 而条件h[a]>=h[b]我还不明觉厉啊..... (脑补:假设一般情况下h[a]==h[b]的,而却有c使得(a, c), pos[c]…
[luogu]P1026 统计单词个数 题目描述 给出一个长度不超过200的由小写英文字母组成的字母串(约定;该字串以每行20个字母的方式输入,且保证每行一定为20个).要求将此字母串分成k份(1<k<=40),且每份中包含的单词个数加起来总数最大(每份中包含的单词可以部分重叠.当选用一个单词之后,其第一个字母不能再用.例如字符串this中可包含this和is,选用this之后就不能包含th). 单词在给出的一个不超过6个单词的字典中. 要求输出最大的个数. 输入输出格式 输入格式: 每组的第…
题目 FJ's \(N (1 ≤ N ≤ 10,000)\) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height \(H (1 ≤ H ≤ 1,000,000)\) of the tallest cow along with the index I…
题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of the tallest cow along with the index I of tha…
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 346  Solved: 184[Submit][Status] Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height…
题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are t…
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3293    Accepted Submission(s): 1272 Problem Description During the War of Resistance Against Japan, tunnel warfare was carried ou…
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 383  Solved: 211[Submit][Status] Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height…
Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 <= H <= 1,000,000) of the tallest cow along with…
题目链接 luogu P1026 统计单词个数 题解 贪心的预处理母本串从i到j的最大单词数 然后dp[i][j] 表示从前i个切了k次最优解 转移显然 代码 #include<cstdio> #include<algorithm> #include<cstring> const int maxn = 507; char a[maxn]; char s[maxn],t[maxn]; int dp[maxn][55]; int n,k,q; int num[maxn][m…
题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of the tallest cow along with the index I of tha…
Language: Default Tallest Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1964   Accepted: 906 Description FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which i…
题目 FJ's N(1≤N≤10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H(1≤H≤1,000,000) of the tallest cow along with the index I of that cow. FJ ha…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 43507   Accepted: 12693 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are getting tired, though, so they want to be able to use as little energy as possible to jump over the hu…
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: [0,1,2,4,5,7] Output: ["0->2","4->5","7"] Explanation: 0,1,2 form a continuous range; 4,5 form a continuous range. Exa…
题目描述: 给定一颗树,求某个节点的子树的val值之和 可以用树的前序遍历给每一个节点编号,从而可以确定一个节点的子树的范围,这样就可以进行直接在区间上进行统计了. vector < int > Map[maxN]写成typedef vector <int> INT; vector <INT> Map(maxN);就不超时了. 线段树 #include <cstdio> #include <cstring> #include <cstdli…
http://poj.org/problem?id=3263 (题目链接) 题意 n头奶牛排成一排,最高的一头I身高H,给出R个条件(a,b),表示a,b之间的奶牛都要比a矮,b的身高大于等于a.求每头奶牛最高能有多高. Solution 差分确实很方便,这样就省去了线段树或者树状数组,而且时间复杂度也少了个log. 考虑对于每个条件(a,b),位于a,b之间的奶牛的身高最多也就是a-1,所以我们将区间[a-1,b-1]全部减去1,然后差分即可. 细节 注意会有重复,所以还要排个序去重..幸好看…
题意略去. 考虑给定的R对pair(A, B). 即A能看见B,这意味着B不比A低,并且区间内部的所有元素的高度严格小于A的高度. 我们规定区间的方向:若A > B,为反方向,反之称为正方向. 容易发现,区间在同一方向上不交叉,即要么相离,要么相互包含. 在相反反方向上,若两区间不相互包含,必定是有且仅有一个公共区间端点. 首先将所有idx上的高度默认设置为H. 对于相离的区间,他们之间的计算是独立的. 考虑相互包含的区间,先考虑范围最大的那个区间,处理之间闭区间[A,B]上的高度是相同的,满足…
一个压了很久的题目,确实很难想,看了别人的做法后总算明白了. 首先要明白一点,因为题目说明了不会有矛盾,所以题目给出来的区间是不能相交的,否则是矛盾的.(原因自己想) 然后既然区间只能是包含的,就很明显了,一个数被包含了几次它就要比最高的牛矮多少. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const i…
题面:P5200 [USACO19JAN]Sleepy Cow Sorting 题解: 最小操作次数(记为k)即为将序列倒着找第一个P[i]>P[i+1]的下标,然后将序列分成三部分:前缀部分(待转移部分),k,后缀部分(不需转移部分). 用树状数组维护前缀部分每一个数挪到后缀部分所需的最小代价(即插到第一个小于它的数前)(这部分完全可以用线段树做). 代码: #include<cstdio> #include<cstring> #include<iostream>…
[题意]n头牛,其中最高h.给定r组关系a和b,要求满足h[b]>=h[a]且a.b之间都小于min(h[a],h[b]),求第i头牛可能的最高高度. [算法]差分 [题解]容易发现r组关系只能包含或不相交. 先假设所有牛是最高高度. 对于一组关系(a,b)显然只需要让区间[a+1,b-1]整体-1就好了.使用差分维护. 特别判断a=b和a=b+1和多区间LR一样的情况. #include<cstdio> #include<algorithm> #include<cst…