BZOJ3314: [Usaco2013 Nov]Crowded Cows】的更多相关文章

3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 86  Solved: 61[Submit][Status] Description Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(i) and has…
从左到右扫一遍, 维护一个单调不递减队列. 然后再从右往左重复一遍然后就可以统计答案了. ---------------------------------------------------------------------------- #include<bits/stdc++.h>   #define rep(i, n) for(int i = 0; i < n; ++i) #define clr(x, c) memset(x, c, sizeof(x)) #define for…
3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 111  Solved: 79[Submit][Status][Discuss] Description Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(…
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define N 50010 using namespace std; struct data { int x,h; }a[N],q[N]; int n,m,l,r; int ok1[N],ok2[N]; inline int read() { ,ans…
http://www.lydsy.com/JudgeOnline/problem.php?id=3314 一眼就是维护一个距离为d的单调递减队列... 第一次写.....看了下别人的代码... 这一题只需要维护距离为d的最大,然后判断最大的是否大于等于自己高度*2 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream>…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3314 题意: N头牛在一个坐标轴上,每头牛有个高度.现给出一个距离值D. 如果某头牛在它的左边,在距离D的范围内,如果找到某个牛的高度至少是它的两倍,且在右边也能找到这样的牛的话.则此牛会感觉到不舒服. 问有多少头会感到不舒服. 题解: 从左到右.从右到左两遍单调队列. 单调性: (1)坐标x递增. (2)高度h递减. 维护单调性: (1)从队首开始,所有与当前牛i的距离超过d的,以后都…
正反两遍个来一次单调队列 DP 即可. Code: #include<cstdio> #include<deque> #include<algorithm> using namespace std; const int maxn = 50000+3; int mark[maxn]; struct Node{ long long pos,height; Node(long long pos=0,long long height=0):pos(pos),height(hei…
3315: [Usaco2013 Nov]Pogo-Cow Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 143  Solved: 79[Submit][Status] Description In an ill-conceived attempt to enhance the mobility of his prize cow Bessie, Farmer John has attached a pogo stick to each of Bes…
3016: [Usaco2012 Nov]Clumsy Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 52[Submit][Status] Description Bessie the cow is trying to type a balanced string of parentheses into her new laptop, but she is sufficiently clumsy (due to h…
树形dp..水 ------------------------------------------------------------------------ #include<cstdio> #include<algorithm> #include<cstring> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i < n ; i++ ) #define clr( x , c…