poj 3263】的更多相关文章

[题目链接] http://poj.org/problem?id=3263 [算法] 若A和B两头牛可以互相看见,那么说明中间的牛的高度都至少比它们少1,因此,我们可以引入一个差分数组c 对于每组关系,我们将c[a+1]减一,c[b]加一 最后,每头牛的最高高度就是 h + c的前缀和 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #includ…
只需不断维护相对值的前缀就能得到解 这种思想第一次是在树状数组区间更新那里看到的,由于题目要求是1~n所以直接可以用前缀和维护 注意不能直接-1 +1 还有POJ的数据..要不是书里有提谁知道会这么毒瘤 /*H E A D*/ int delta[maxn]; map<P,int> vis; int main(){ int n,I,h,r,a,b; while(~iin(n)){ I=read();h=read();r=read(); memset(delta,0,sizeof delta);…
题目大意 POJ链接 给出\(n\)头牛的身高,和\(m\)对关系,表示牛\(a[i]\)与\(b[i]\)可以相互看见.已知最高的牛为第\(p\)头,身高为\(h\). 求每头牛的身高最大可能是多少. (老姚的翻译好像改变量名了昂,但是无所谓) 输入格式 第一行四个整数\(n,p,h,m\),表示见题意, 接下来\(m\)行,每行两个正整数表示\(a[i],b[i]\). 输出格式 \(n\)行整数表示每头牛的最大可能身高. 数据范围 \(1\le n\le 10000,1\le h\le 1…
一个压了很久的题目,确实很难想,看了别人的做法后总算明白了. 首先要明白一点,因为题目说明了不会有矛盾,所以题目给出来的区间是不能相交的,否则是矛盾的.(原因自己想) 然后既然区间只能是包含的,就很明显了,一个数被包含了几次它就要比最高的牛矮多少. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const 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…
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…
题意: 思路: 对于每一个区间 [a,b] [a+1,b-1]肯定是比a,b低至少1的 因为题目要求最大值 所以就直接差分一下 搞之 (复杂度 O(n)) Discuss里说有重复的数据 用set判一下重就好了复杂度O(nlogn) //By SiriusRen #include <set> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int N…
传送门 解题思路 如果x与y互相看见,那么他们一定比之间的高,所以给他们之间的高度-1,最后得到的答案是所有牛的高度+h,之间-1会T,用差分数组或线段树维护即可. 代码 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> using namespace std; const in…
题目 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…
Codeforces Round #688 (Div. 2) 题目:B. Suffix Operations 题意:给定一个长为n的数组a,你可以进行两种操作:1).后缀+1;     2)后缀-1:  问需要最少多少步操作你才能使得数组中元素全部相等,并且首先你可以改变其中任何一个元素成为任何一个数,并且不被计入步数 思路: 首先来看一下数组中大致分为这三种情况:举例 3 5 7   (上升式)这样中间的5变成3-7之间的任何一个数都能最终变成3 7 5 3 (下降式)与上述相同 7 3 5…