洛谷 P2947 [USACO09MAR]仰望Look Up】的更多相关文章

P2947 [USACO09MAR]仰望Look Up 74通过 122提交 题目提供者洛谷OnlineJudge 标签USACO2009云端 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 中文翻译应当为向右看齐 题目中文版范围.. 题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Co…
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000). Each cow is looking to her left toward those with higher index numbers. We say that cow…
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000). Each cow is looking to her left toward those with higher index numbers. We say that cow…
目录 题目 思路 \(Code\) 题目 戳 思路 单调栈裸题 \(Code\) #include<stack> #include<cstdio> #include<string> #include<cstring> #include<iostream> #define MAXN 100001 #define rr register using namespace std; int n,ans[MAXN]; struct mu{ int num,…
#include<cstdio> #include<algorithm> #include<stack> #include<cctype> using namespace std; struct cow{ int id; int data; cow(,):id(id),data(data){ } }ans[]; stack<cow> q; int n,tmp,cnt; inline bool cmp(const cow &a,const…
向右看齐 题目链接 此题可用单调栈O(n)求解 维护一个单调递减栈,元素从左到右入栈 若新加元素大于栈中元素,则栈中元素的仰望对象即为新加元素 每次将小于新加元素的栈中元素弹出,记录下答案 #include<iostream> #include<cstdio> using namespace std; #define N 100010 int n,w[N],stack[N],top,ans[N]; int main() { scanf("%d",&n);…
题目传送门 大概思路就是把这两个数组排序.在扫描一次,判断大小,累加ans. #include<bits/stdc++.h> using namespace std; int x,y,z; ],m[]; long long s; int main(){ cin>>z>>x>>y; ;i<=z;i++) cin>>n[i]>>m[i]; sort(n+,n++z); sort(m+,m++z); ;i<=z;i++){ if…
https://www.luogu.org/problem/show?pid=2944 题目描述 Wisconsin has had an earthquake that has struck Farmer John's farm! The earthquake has damaged some of the pastures so that they are unpassable. Remarkably, none of the cowpaths was damaged. As usual,…
传送门 题目大意: ai,ai+1,ai+2... 变成 bi,bi+1,bi+2.. 不计顺序,增加和减少a数组均有代价. 题解:贪心+排序 小的对应小的 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #define N 25009 #define LL long long using namespace std; int n,x,y; LL an…
题目:https://www.luogu.org/problemnew/show/P2943 一下想到n^2.然后不会了. 看过TJ之后似乎有了新的认识. n^2的冗余部分在于当后面那部分的种类数一样时,只需用最前面的dp转移过来即可. 所以如果枚举的是后面那部分的种类数,对于每个种类数记录一下最前面的dp,也许会好一些. 但是种类也有n种,怎么办? 考虑是否需要枚举全部从1~n. k*k是一个比较大的数.发现一定有一种情况使得时间花费为n(即全部单个选),所以只需要枚举k*k<=n的种类数即可…