题目描述 Farmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are facing forward, like good cows. Some of them are facing backward, though, and he needs them all to face forward to make his life perfect. Fortunately, FJ recently…
P2882 [USACO07MAR]面对正确的方式Face The Right Way $n<=5000$?枚举翻转长度,顺序模拟就ok了 对于每次翻转,我们可以利用差分的思想,再搞搞前缀和. (输出反了还交,真菜) #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 10010 int n,a[N],s[N],p[N],ans,mnd=1e9;…
题目概括 题目描述 Farmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are facing forward, like good cows. Some of them are facing backward, though, and he needs them all to face forward to make his life perfect. Fortunately, FJ rece…
题目传送门 题目描述 Farmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are facing forward, like good cows. Some of them are facing backward, though, and he needs them all to face forward to make his life perfect. Fortunately, FJ rec…
洛谷题目传送门 费了几个小时杠掉此题,如果不是那水水的数据的话,跟列队的难度真的是有得一比... 话说蒟蒻仔细翻了所有的题解,发现巨佬写的都是倍增,复杂度是\(O(n\log n\log nw)\)的,貌似还不够优秀. 其实我们与其对于每一个点都通过倍增向上找到对应位置,还不如直接从上到下dfs一遍,判断:如果当前点子树内初始位置最浅的军队与当前点距离不超过\(mid\),或者所有子树都被封锁,那么当前点也被封锁. 这样以后再二分,时间复杂度降至\(O(n\log nw)\).其它部分的思路Da…
P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow down the list of features shared by his cows to a list of only K different features (1 ≤ K ≤ 30). For ex…
P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow down the list of features shared by his cows to a list of only K different features (1 ≤ K ≤ 30). For ex…
P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维) 前言 题目链接 本题作为一道Stl练习题来说,还是非常不错的,解决的思维比较巧妙 算是一道不错的题 思路分析 第一眼看到这题,我还以为是数据结构题,看来半天没看出来数据结构咋做(我还是太菜了) 我们对\(m\)种能力有\(n\)次操作,需要找到对每种能力提升相同的最大操作区间的长度,求最大 区间,我们考虑维护这\(m\)种技能提升值的前缀和,假设第\(l+1\)次操作到第\(r\)次操作对\(m\…
题目 不得不说这个题非常毒瘤. 简化题意 这个题的暴力还是非常好想的,完全可以过\(50\%\)的数据.但是\(100\%\)就很难想了. 因为数据很大,所以我们需要用\(O(\sqrt n)\)的时间求出每个时间的前面第一个跟它满足均衡区间的时间. 此时我们会很快速的想到\(Hash\)或\(Map\),他们的时间复杂度是小于\(O(\sqrt n)的\)所以满足要求,因此一般看到寻找相同得值的时候,最好还是想想怎么优化吧 \(Code\) #include <iostream> #incl…
题意 题目链接 Sol 显然如果题目什么都不说的话需要\(\frac{n * (n - 1)}{2}\)个相对关系 然后求一下传递闭包减掉就行了 #include<bits/stdc++.h> using namespace std; const int MAXN = 1001; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f =…