CF-1132 C.Painting the Fence】的更多相关文章

[luogu P2205] [USACO13JAN]画栅栏Painting the Fence 题目描述 Farmer John has devised a brilliant method to paint the long fence next to his barn (think of the fence as a one-dimensional number line). He simply attaches a paint brush to his favorite cow Bessi…
P2205 画栅栏Painting the Fence 题目描述 \(Farmer\) \(John\) 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长度代表一块栅栏)他只是简单的把刷子蘸满颜料,系在他最喜欢的奶牛\(Bessie\)上,然后让\(Bessie\)来回地经过围墙,自己则在一旁喝一杯冰镇的凉水.(---_-|||) \(Bessie\) 经过的所有围墙都会被涂上一层颜料.\(Bessie\)从围墙上的位置\(0\)出发,并将会进行\(…
Painting The Fence(贪心+优先队列) 题目大意:给 m 种数字,一共 n 个,从前往后填,相同的数字最多 k 个在一起,输出构造方案,没有则输出"-1". 解题思路:贪心的思路,优先选择数量多的先填,这样会让最后剩余相同的数字数量最少,所以我们优先选数量最多的两种数字填,最后剩下的(某一种)就填到它前面的位置去,一定是和相同的填在一起,这里就不证明了,自己画下就可以得到.优先队列模拟即可. AC_Code /* */ #include <bits/stdc++.…
https://codeforces.com/contest/1132/problem/C 采用逆向思维,要求最大的覆盖,就先求出总的覆盖,然后减去删除两个人贡献最少的人 #include<iostream> #include<vector> #include<algorithm> using namespace std; vector<]; ][],con1[];//一维数组:这个人的贡献,二维数组:这两个人共同的贡献 int main(){ int n,q;…
链接 [https://codeforces.com/contest/1132/problem/C] 题意 就是有个n长的栅栏,然后每个油漆工可以染的区域不同 给你q让你选出q-2个人使得被染色的栅栏最多 分析 一开始一直想着用dp,就是那个状态转移无法搞. 后面是看别人的思路才发现,暴力就可以了,具体看代码 O(n*q)复杂度.还是太菜了 代码 #include<bits/stdc++.h> using namespace std; #define ll long long const in…
There is a beautiful fence near Monocarp's house. The fence consists of nn planks numbered from left to right. The ii -th plank has color aiai . Monocarp's father have decided to give his son mm orders. Each order is a color cjcj . After each order M…
Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数量. 思路:首先枚举第一个删掉的区间,然后我们可以通过差分来求出每个格子被多少个区间覆盖了,随后求出所有格子中被\(1\)个区间覆盖的数量的前缀和,再枚举第二个删掉的区间,找删掉的\(1\)个区间覆盖的最少的即为答案. Codeforces 1132 C 分析 tataky: 首先我们将所有的互不包含的区间们放在\(v\)里,然后看被包含的区间有多少,如果超过2个就直接输…
题目链接:https://codeforces.com/contest/1132/problem/C 题意: 栅栏有 $n$ 个节,有 $q$ 个人可以雇佣来涂栅栏,第 $i$ 个人可以涂第 $l_i$ 节到第 $r_i$ 节. 但是现在预算紧张,所以只能雇佣 $q-2$ 个人,你想确认雇佣哪 $q-2$ 个人使得涂色栅栏的节数最大. 题解: 首先看到 $n$ 的范围,就可以想到大概可以枚举第一个不雇佣的人再枚举第二个不雇佣的人,时间复杂度在 $O(n^2)$ 左右. 先假定第一个不雇佣的人是第…
题目链接 https://vjudge.net/problem/CodeForces-1132C 题面 Description You have a long fence which consists of \(n\) sections. Unfortunately, it is not painted, so you decided to hire \(q\) painters to paint it. \(i\)-th painter will paint all sections \(x\…
题目描述 Farmer John has devised a brilliant method to paint the long fence next to his barn (think of the fence as a one-dimensional number line). He simply attaches a paint brush to his favorite cow Bessie, and then retires to drink a cold glass of wat…
题意就是给出多个区间,要求去掉两个区间,使得剩下的区间覆盖范围最大. 当然比赛的时候还是没能做出来,不得不佩服大佬的各种姿势. 当时我想的是用线段树维护区间和,然后用单点判0,维护区间间断个数.然后打到一半,就发现想法有问题. 这道题正解就是简单的前缀和,或者DP. 我为了更加深入理解,两种方法都试了试. 前缀和版本: 由于题目给的范围是5000,明显支持N^2,于是我们枚举去掉的两个,刚好满足,那么要如何才能O(1)的得到答案? 我们其实可以这样,我们知道它的总覆盖的数目,这是非常容易求出的.…
传送门 题意: 庭院中有 n 个围栏,每个围栏上都被涂上了不同的颜色(数字表示): 有 m 条指令,每条指令给出一个整数 x ,你要做的就是将区间[ x第一次出现的位置 , x最后出现的位置 ]中的围栏 全部涂成 x ,经过 m 次操作后,输出每个围栏的涂色情况: 题解: 比赛的时,在读完题后,一瞬间,想到了线段树的区间更新,懒惰标记,but 我已经好久好久没写过线段树的代码了(嫌代码太长,逃): 所以,比赛时,就不了了之,去看其他题了: 今天,温习了一下线段树的用法,重新思考了本题的解题思路,…
区间dp.. 每次删一串相邻的一样的,问多少次删光. 感觉想的几乎是一样的怎么比赛时就过不了呢...一定是因为我挂机睡觉了 考虑l和r相等,l和l+1相等,r和r-1相等这三种情况就行了..然后就是裸的区间dp.. 上紫计划再次流产.jpg 和bzoj1260一样的? #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int dp[N][N]; int n; string s; int min(int a…
传送门 题目大意: 开始站在原点,给出一系列操作 x L/R,表示向左或向右走几步. 最多会移动到离原点1,000,000,000单位远的地方. n次操作,n<=100000 问走过k次的地方有几个 题解:离散化+差分 看了官方题解,很明白. 发现n<=100000,看出所到达的不同的点最多只有100001个 这个是可以用数组存的,用到了坐标压缩的思想,很重要. pos[i]表示第i次走的点的位置. C[]是差分数组. 代码: #include<iostream> #include…
题目大意:现在有n个栅栏板,p个工人,每个工人可以涂一段区间的栅栏板,问如果雇佣p-2个工人,最多可以涂多少块栅栏板. 做法:先求出q个工人能涂得最多木板数,并统计每个木板被涂的次数.求被涂一次的木板个数和被涂两次的木板个数的前缀和. 暴力枚举选择去掉哪两个工人,并且看看能删掉几个木板.即可 #include<iostream> #include<cstdio> #define maxn 5010 using namespace std; int n,p,l[maxn],r[max…
题目大意: 给定n m 接下来给定m个在n范围内的段的左右端 l r 求选取m-2段 最多能覆盖多少格 #include <bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f #define mem(i,j) memset(i,j,sizeof(i)) #define inc(i,l,r) for(int i=l;i<=r;i++) #define dec(i,r,l) for(i…
题目大意: 输入n,k :n次操作 找到覆盖次数在k及以上的段的总长 一开始位置在0 左右活动范围为1-1000000000 接下来n行描述每次操作的步数和方向 Sample Input 6 22 R6 L1 R8 L1 R2 R Sample Output 6 下面的方法用了 map 和 区间表示法 http://www.cnblogs.com/zquzjx/p/8321466.html(区间表示法看这里) 但是不同于 题解 https://www.luogu.org/problemnew/s…
因为cf上一堆水题,每个单独开一篇博客感觉不太好,就直接放一起好了. CF1096D Easy Problem 给定字符串,每个位置删除要代价.求最小代价使之不含子序列"hard". 设f[i][f]表示前i个删到只匹配f位子序列的最小代价.转移看代码吧.O(n) #include <bits/stdc++.h> typedef long long LL; ; int a[N]; LL f[N][]; char str[N]; int main() { int n; sca…
"Holiday is coming, holiday is coming, hurray hurray!" shouts Joke in the last day of his college. On this holiday, Joke plans to go to his grandmother's house located in Schematics village. Joke's grandmother's house is more than a hundred year…
A.Regular bracket sequence A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting…
P2205 画栅栏Painting the Fence 题目描述 \(Farmer\) \(John\) 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长度代表一块栅栏)他只是简单的把刷子蘸满颜料,系在他最喜欢的奶牛\(Bessie\)上,然后让\(Bessie\)来回地经过围墙,自己则在一旁喝一杯冰镇的凉水.(---_-|||) \(Bessie\) 经过的所有围墙都会被涂上一层颜料.\(Bessie\)从围墙上的位置\(0\)出发,并将会进行\(…
A. Regular Bracket Sequence 题意:给出四种括号的数量 ((  )) ()  )( 问是否可以组成合法的序列(只能排序不能插在另外一个的中间) 思路: 条件一:一个或 n个)( 都可以组成 )()()( 这种结构 这只需要 一个((和一个))就可以合成合法的序列 条件二: (( 和))需要相等 ()本身就合法不用管 ude<bits/stdc++.h> #define FOR(i,f_start,f_end) for(int i=f_startl;i<=f_en…
A .Regular Bracket Sequence 题意:给定“((” , “()” ,  “)(”,  “))”四种,问是否可以组成合法括号匹配 思路:设四种是ABCD,B可以不用管,而C在A或者D存在时可以不考虑,然后就是A=D. #include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; ; ll A,B,C,D,ans; i…
A. Regular Bracket Sequence 显然,"\(()\)"不影响结果它是自我匹配的,可以把所有的\(((\)和\())\)都放在左边/右边,这样只要检查它们的数目就行,还有个坑点,就是如果\()(\)多于一,需要给左右两边一个负担,必须小于它们的数量才行. #include <cstdio> #include <iostream> using namespace std; int c1, c2, c3, c4; int main(){ sca…
2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage A. Coffee Break 排序之后优先队列搞一下就好了 //#pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using name…
http://codeforces.com/problemset/problem/448/C 题目大意:给你一个栅栏,每次选一横排或竖排染色,求把全部染色的最少次数,一个点不能重复染色. 和这道题有点像,不过可以竖着. 考虑横着涂一次的情况,那么有两个显而易见的事实. 1.这次涂色长度必须尽可能大. 2.在这次涂色区域的下方,必定都是横着涂的. 所以,对于一串栅栏h 1 , h 2 , ... , h n ,如果要横着涂,就必定要从底向上涂min⁡{h 1 , h 2 , ... , h n }…
E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter w…
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion d…
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his…
Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap between them. Afte…