448C - Painting Fence(分治)】的更多相关文章

Painting fence 题意 乍一看以为是之前做过的一道单调队列优化的DP,不是. 也是有n块木板,每个木板宽1米,有一个高度ai,现在要把他们刷成橘色,给了你一个宽一米的刷子,你可以横着刷,或者竖着刷,问最少需要刷几下才能将所有的木板着色. 思路 对于一个区间[l,r]的木板来说,第一步要么把所有的木板都竖着刷,要么把最低的木板横着刷一遍,问题变为区间所有的木板减去最短木板的高度之后,刷分为的两个小区间的次数和+最短木板高度.两者取最小值即可.分治 代码 #include<bits/st…
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…
题意:给出宽为1高为Ai的木板n条,排成一排,每次上色只能是连续的横或竖并且宽度为1,问最少刷多少次可以使这些木板都上上色 分析:刷的第一步要么是所有的都竖着涂完,要么是先横着把最矮的涂完,如果是第一种,那么ans等于n,如果是第二种,那么ans=最矮的高度+被刷掉最矮的后,新的几段不连续木板最小上色次数,所以用分治可以解决这个问题 AC代码: #include <bits/stdc++.h> using namespace std; #define ll long long const in…
2017-08-02 14:27:18 writer:pprp 题意: • 每块木板宽度均为1,高度为h[i] • n块木板连接为宽度为n的栅栏 • 每次可以刷一横或一竖(上色) • 最少刷多少次可以使得栅栏被全部上色 • 1 ≤ n ≤ 5000 算法分析:可以横着刷,可以竖着刷,横着刷是为了减小竖着刷的次数 采用分治,每个分治中都取横着刷和竖着刷两者的最小值 代码及说明如下: #include <iostream> #include <queue> using namespac…
题目链接:http://codeforces.com/problemset/problem/448/C 题意: 有n个木板竖着插成一排栅栏,第i块木板高度为a[i]. 你现在要将栅栏上所有地方刷上油漆. 每次你可以选择竖着刷或横着刷,但必须保证一次刷的地方不能间断. 问你至少要刷几次才能刷满. 题解: 首先有一个贪心结论: 对于当前要刷的一片区域,令minn为这片区域的最小高度. 如果选择横着刷,则至少要将区域底部的minn层刷完. 如图,至少要将下面两层刷完: 然后考虑如何分治: 对于当前的这…
Description Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap b…
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 favorite color, orange. The fence is represent…
题目链接:http://codeforces.com/contest/448/problem/C 题目大意:n个1* a [ i ] 的木板,把他们立起来,变成每个木板宽为1长为 a [ i ] 的栅栏,现在要给栅栏刷漆,刷子宽1,刷子可以刷任意长,每次只能横着刷或者竖着刷,问最少需要刷几次?解题思路:参考了这里(https://blog.csdn.net/qq_24451605/article/details/48492573)首先我们能够想到,如果横着刷,为了得到最优解,当前刷的位置的下面也…
http://codeforces.com/problemset/problem/448/C 题目大意:给你一个栅栏,每次选一横排或竖排染色,求把全部染色的最少次数,一个点不能重复染色. 和这道题有点像,不过可以竖着. 考虑横着涂一次的情况,那么有两个显而易见的事实. 1.这次涂色长度必须尽可能大. 2.在这次涂色区域的下方,必定都是横着涂的. 所以,对于一串栅栏h 1 , h 2 , ... , h n ,如果要横着涂,就必定要从底向上涂min⁡{h 1 , h 2 , ... , h n }…
略有上升称号,最近有很多问题,弥补啊,各类竞赛滥用,来不及做出了所有的冠军.这个话题 这是一个长期记忆的主题.这是不是太困难,基本技能更灵活的测试,每次我们来看看这个问题可以被删除,处理然后分段层,贪婪的想法画一幅画,可以发现,下一步骤是如何应用,搜递归就能够了.当时写错了.还是漏了一些,如今补题才发现,长记性咯 http://codeforces.com/contest/448/problem/C #include<iostream> #include<cstdio> #incl…
[题解]Painting Fence 分治模板.贪心加分治.直接\(O(n^2logn)\)分治过去.考虑一块联通的柱形是子问题的,是递归的,贪心分治就可.记得对\(r-l+1\)取\(min\). 上好看的代码 #include<bits/stdc++.h> #define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t) #define DRP(t,a,b) for(register int (t)=(a),edd_=(…
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…
题目链接:http://codeforces.com/problemset/problem/448/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. B…
递归.分治. . . 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 ol…
解题报告 给篱笆上色,要求步骤最少,篱笆怎么上色应该懂吧,.,刷子能够在横着和竖着刷,不能跳着刷,,, 假设是竖着刷,应当是篱笆的条数,横着刷的话.就是刷完最短木板的长度,再接着考虑没有刷的木板,,. 递归调用,,. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define inf 999999999999999 using namespace…
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…
C. Painting Fence Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no…
Painting Fence Time Limit:1000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Description Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorit…
题目链接:http://codeforces.com/problemset/problem/448/C 题目大意:用宽度为1的刷子刷墙,墙是一长条一长条并在一起的.梳子可以一横或一竖一刷到底.求刷完整面墙最少要几次. 关键思路:很有意思,我们会发现,一座墙,从最短的那根往下的矩形区域,全刷完后会形成多座“小山”,这和最先要刷的墙形状是一样的.所以问题就可以进行分治了. 代码如下: //图像类比 #include<iostream> #include<algorithm> using…
题面 \(solution:\) 一道蛮水的分治题,但思想很不错(虽然我还是非常天真的以为是积木大赛原题,并且居然还有30分) 看到这个题目,根据贪心的一贯风格,我们肯定能想到将整个栅栏的下面某部分直接用几次横向的操作把它涂掉.然后我们发现如果将涂了色的部分不管,整段栅栏会被我们分成若干个部分(最短的竖条栅栏因为贪心会被横着涂完,然后整个栅栏会被分为左(中)右几个部分).然后我们将这几个依次用这种办法分治.再然后我们发现我们好像把纵向操作忘记了,它在什么地方用呢?我们在每一次求某段栅栏最小次数时…
传送门 Descriptionzed 最近总是受到 Farmer 的困扰,因此他在自家的门前插了一排栅栏以防农气的入侵.栅栏由 N 个竖条栅栏横向组成,每个竖条栅栏宽度为 1.过了一段时间,zed 觉得栅栏非常不美观.因此,他想给栅栏涂上颜色.问题是,zed的刷子宽度只有 1,也就是说,一次只能将连续的一排或一列格子涂上颜色(长度任意).zed 想用最少的次数把栅栏全部涂上颜色(注意,一个格子不能重复涂色).但是 zed 现在没时间,所以这个问题就交给你了. Input第一行为一个整数 N,代表…
http://codeforces.com/contest/448/problem/C 题意:给你n宽度为1,高度为ai的木板,然后用刷子刷颜色,可以横着刷.刷着刷,问最少刷多少次可以全部刷上颜色. 思路:dp[i][j] 表示在第i列以后的木板都已刷完且第j列的木板是横着刷的,最少需要的次数.如果a[i]>=a[j]的情况,比较再竖着刷一次和横着刷哪一个情况次数少. #include <cstdio> #include <iostream> #include <cst…
洛谷 Codeforces 建议阅读这篇博客作为预备.无耻地打广告 思路 与bzoj4025很相似,思路也差不多,可以看上面那篇博客. 仍然是用二分图的充要条件:没有奇环. 然而这题难在每条边的存在时间不固定,无法一开始知道. 可以每次在加入这条边的时间点判断能否成功修改,确定接下来一段时间它的颜色是什么. 具体见代码. 代码 #include<bits/stdc++.h> namespace my_std{ using namespace std; #define pii pair<i…
[题目链接]:click here~~ [题目大意]:题意:你面前有宽度为1,高度给定的连续木板,每次能够刷一横排或一竖列,问你至少须要刷几次. Sample Input Input 5 2 2 1 2 1 Output 3 Input 2 2 2 Output 2 Input 1 5 Output 1 搜索: // C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include &…
A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main(){ double a1,a2,a3; double b1,b2,b3; int n; cin…
B. Suffix Structure 1. 先判断s去掉一些元素是否能构成t,如果可以就是automaton 判断的方法也很简单,two pointer,相同元素同时++,不相同s的指针++,如果t能全找到,那么s能够去掉元素构成t. bool f(string s, string t) { , j = ; while (i < s.size() && j < t.size()) { if (s[i] == t[j]) { i++; j++; } else { i++; }…
A:Rewards: 题目链接:http://codeforces.com/problemset/problem/448/A 题意:Bizon有a1个一等奖奖杯,a2个二等奖奖杯,a3个三等奖奖杯,b1个一等奖奖牌,b2个二等奖奖牌,b3个三等奖奖牌,和一个有n个架子的橱柜.如今Bizon想把这些奖牌和奖杯放在橱柜里,可是要遵循以下的规则:一个架子上不能同一时候放奖杯和奖牌:一个架子上的奖杯数量不能超过5个.奖牌数量不能超过10个. 问能不能把这些奖杯和奖牌所有放进去. 分析:依照贪心原则.一个…
Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present - a new glass cup…
[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…