Balanced Photo(USACO)】的更多相关文章

题目大意: 我们有一个数列,数列中有n个数,对于一个数ai,在它左边的比他大的数的个数为li,右边比他大的数的个数为ri,若li,ri中的较大者比较小者的两倍还大,那么他就是一个不平衡数,求不平衡数的数量. ————————————————我是分割线———————————————— 好吧,典型逆序对. 因为我们要求左边比他大的数的个数,所以我们倒着排序,然后再离散. 然后树状数组解决问题. 那么右边怎么办? 很显然我们得到的离散数组的值就是比他大的数的个数+1(它本身),所以右边的答案为:离散数…
P3608 [USACO17JAN]Balanced Photo平衡的照片 题目描述 Farmer John is arranging his NN cows in a line to take a photo (1 \leq N \leq 100,0001≤N≤100,000). The height of the iith cow in sequence is h_ih​i​​, and the heights of all cows are distinct. As with all ph…
[题目链接] 点击打开链接 [算法] 树状数组 [代码] #include<bits/stdc++.h> using namespace std; int i,N,ans,l1,l2; ],val[],id[]; template <typename T> void read(T &x) { ; ; ; } +c-'; x*=f; } bool cmp(int a,int b) { return val[a] > val[b]; } int lowbit(int x)…
既然是bronze,毫无压力的AC了. 就是个深搜,当然加个剪枝--最后一个组不用搜. 恩可以一个一个组分层次dfs,这样会跑得飞起~~也不容易错 #include <cstdio> int f[13],i,su,tt1,tt2,lev[4],min; bool has[13]; inline int md(int a,int b,int c,int d){ tt1=a,tt2=a; if(tt1<b)tt1=b; if(tt1<c)tt1=c; if(tt1<d)tt1=d…
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4759 [题解] 排序,从大到小插入,树状数组统计. # include <vector> # include <stdio.h> # include <string.h> # include <iostream> # include <algorithm> // # include <bits/stdc++.h> using n…
题目链接:https://www.luogu.org/problemnew/show/P3608 乍一看很容易想到O(N^2)的暴力. 对于每个H[i]从i~i-1找L[i]再从i+1~n找R[i],然后比较. 60分(数据够水) 但是这个思路就是很直白的模拟,让人不容易想到如何去优化. 然后我们换一个也是差不多O(N^2)的思路: 我们设法把H[i]所对应的第k大的k求出来. for example: H 34 6 23 0 5 99 2 Kth 2 4 3 7 5 1 6 那么我们就能发现,…
传送门 树状数组裸题 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 100001 using namespace std; int n, m, ans; int a[N], b[N], R[N], L[N], c[N]; inline int read() { int x = 0, f = 1; char ch = getchar…
题目链接 Solution 先离散化,然后开一个大小为 \(100000\) 的树状数组记录前面出现过的数. 然后查询 \((h[i],n]\) 即可. 还要前后各做一遍. Code #include<bits/stdc++.h> #define N 200008 #define ll long long using namespace std; void in(ll &x) { char ch=getchar();ll f=1,w=0; while(ch<'0'||ch>…
题目链接:https://www.luogu.com.cn/problem/P3608 方法一 用树状数组求逆序对先后扫两遍,一次从前往后,一次从后往前,算出每头奶牛左右两边比她高的数量. 最后统计一下. #include <bits/stdc++.h> using namespace std; int sum[500010], l[100010], r[100010]; int n, m, u, v, a[500010], t[500010]; int ans; inline int rea…
随时可能弃坑. 因为不知道最近要刷啥所以就决定刷下usaco. 优先级排在学习新算法和打比赛之后. 仅有一句话题解.难一点的可能有代码. 优先级是Gold>Silver.Platinum刷不动...(可能有一两道?) 2015 Feb Gold BZOJ3939. [Usaco2015 Feb]Cow Hopscotch 这题洛谷数据过水,\(O(n^4)\)的dp跑的飞快...所以建议在bzoj写. 但是还是要考虑一下4次方的dp的...其实就是强行枚举转移点,我们可以试着维护前缀和,那么只要…
P2207 Photo 题目描述 Framer Jhon 打算给他的N头奶牛照相,( 2 <= N <= 1 000 000 000) . 他们排成一条线,并且依次取1~N作为编号. 每一张照片可以拍摄到这列奶牛中一个连续的区间中的奶牛. 对于每一头奶牛,FJ都想要让Ta至少出现在一张照片里. 不幸的是,有K对关系不好的奶牛( 1 <= K <= 1000),他们拒绝出现在同一张照片里. 已知所有关系不好的奶牛所在的位置,请计算出FJ需要的最小需要拍摄的照片数量. 输入输出格式 输…
[题目链接] 点击打开链接 [算法] 这是一道经典的最值查询(RMQ)问题. 我们首先想到线段树.但有没有更快的方法呢?对于这类问题,我们可以用ST表(稀疏表)算法求解. 稀疏表算法.其实也是一种动态规划的算法.是先做一遍预处理,然后O(1)求出答案.                设计状态 : f[i][j] 表示从第i个数开始连续2^j次方个数(包括第i个数),中的(最大或最小值) 那么状态转移方程是什么呢? 我们知道 2^j可分解为两个2^(j-1),所以f[i][j] = max或min…
[简●解][USACO] 照片Photo [题目大意] 在\(1\)~\(N\)的序列上有\(M\)个区间,使得这\(M\)个小区间每个覆盖了且仅覆盖了一个点,求最多点数,如果无解,输出\(-1\). [分析] 刚开始做的时候我是懵的...不管三七二十一开始想差分约束系统,无奈没那么好的思维,没想出来... 一翻题解,,\(WOC!!!\)这是什么神仙\(DP?\)真的是学到了... 我们设\(f[i]\)表示序列的第\(i\)位是一个点时,序列\(1\)~\(i\)的最多点数. 那么\(dp\…
\(\\\) Description 有一个长度为 \(n\) 的奶牛队列,奶牛颜色为黑或白. 现给出 \(m\) 个区间 \([L_i,R_i]\) ,要求:每个区间里 有且只有一只黑牛 . 问满足所有给出限制最少有多少头黑牛,若无合法方案输出 \(-1\) . \(n\le 2\times 10^5,m\le 10^5\) \(\\\) Solution 单调队列优化. 设 \(f[i]\) 表示,第 \(i\) 个位置为黑牛, \([1,i]\) 的设置符合所有限制,最少有多少头黑牛. 考…
poj 3264 http://poj.org/problem?id=3264 洛谷 P2880 https://www.luogu.org/problemnew/show/P2880 题目描述 For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimat…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 32820   Accepted: 15447 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh…
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 40493 Accepted: 19035 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John de…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 45243   Accepted: 21240 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh…
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 41548 Accepted: 19514 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John de…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 44720   Accepted: 20995 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh…
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10924 Accepted: 3244 Description 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 h…
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13215 Accepted: 3873 Description 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 h…
大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草   裸背包 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 神转化,筛法 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐  LIS 1610: [Usaco2008 Feb]Line连线游戏 排序 1611: [Usaco2008 Feb]Meteor Shower流星雨  BFS 1612: [Usaco2008…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34306   Accepted: 16137 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34306   Accepted: 16137 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34140   Accepted: 16044 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 53703   Accepted: 25237 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh…
UPD:我真不是想骗访问量TAT..一开始没注意总长度写着写着网页崩了王仓(其实中午的时候就时常开始卡了= =)....损失了2h(幸好长一点的都单独开了一篇)....吓得赶紧分成两坨....TAT.............. —————————————————————————————————————————————————————————————————————————————— 写(被虐)了整整一个月b站上usaco的金组题...然而到现在总共只写了100道上下TAT(当然是按AC人数降序排…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organi…
传送门:http://poj.org/problem?id=3264 Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 66241   Accepted: 30833 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in…