题目大意:现在有n个栅栏板,p个工人,每个工人可以涂一段区间的栅栏板,问如果雇佣p-2个工人,最多可以涂多少块栅栏板。

做法:先求出q个工人能涂得最多木板数,并统计每个木板被涂的次数。求被涂一次的木板个数和被涂两次的木板个数的前缀和。

暴力枚举选择去掉哪两个工人,并且看看能删掉几个木板。即可

#include<iostream>
#include<cstdio>
#define maxn 5010
using namespace std;
int n,p,l[maxn],r[maxn],a[maxn],sum1[maxn],sum2[maxn],ans,cur;
int main(){
scanf("%d%d",&n,&p);
for(int i=;i<=p;i++)scanf("%d%d",&l[i],&r[i]);
for(int i=;i<=p;i++)
for(int j=l[i];j<=r[i];j++)
a[j]++;
for(int i=;i<=n;i++){
sum1[i]=sum1[i-];
sum2[i]=sum2[i-];
if(a[i]==)sum1[i]++;
if(a[i]==)sum2[i]++;
if(a[i])cur++;
}
// for(int i=1;i<=n;i++)printf("%d ",sum1[i]);puts("");
// for(int i=1;i<=n;i++)printf("%d ",sum2[i]);puts("");
for(int i=;i<=p;i++){
for(int j=i+;j<=p;j++){
int now=cur;
int l1=l[i],r1=r[i],l2=l[j],r2=r[j];
if(l1>l2){
swap(l1,l2);
swap(r1,r2);
}
if(r1<l2){//两个区间互不覆盖
now-=sum1[r1]-sum1[l1-];
now-=sum1[r2]-sum1[l2-];
}
else{
int l3=max(l1,l2);
int r3=min(r1,r2);
now-=sum1[r1]-sum1[l1-];
now-=sum1[r2]-sum1[l2-];
now-=sum2[r3]-sum2[l3-];
}
ans=max(ans,now);
}
}
printf("%d\n",ans);
return ;
}

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

  1. [luogu P2205] [USACO13JAN]画栅栏Painting the Fence

    [luogu P2205] [USACO13JAN]画栅栏Painting the Fence 题目描述 Farmer John has devised a brilliant method to p ...

  2. 洛谷 画栅栏Painting the Fence 解题报告

    P2205 画栅栏Painting the Fence 题目描述 \(Farmer\) \(John\) 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长 ...

  3. Painting The Fence(贪心+优先队列)

    Painting The Fence(贪心+优先队列) 题目大意:给 m 种数字,一共 n 个,从前往后填,相同的数字最多 k 个在一起,输出构造方案,没有则输出"-1". 解题思 ...

  4. Educational Codeforces Round 61 Editorial--C. Painting the Fence

    https://codeforces.com/contest/1132/problem/C 采用逆向思维,要求最大的覆盖,就先求出总的覆盖,然后减去删除两个人贡献最少的人 #include<io ...

  5. C. Painting the Fence

    链接 [https://codeforces.com/contest/1132/problem/C] 题意 就是有个n长的栅栏,然后每个油漆工可以染的区域不同 给你q让你选出q-2个人使得被染色的栅栏 ...

  6. Painting the Fence Gym - 101911E(构造)

    There is a beautiful fence near Monocarp's house. The fence consists of nn planks numbered from left ...

  7. 【Codeforces 1132C】Painting the Fence

    Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数量. 思路:首先枚举第一个删掉的区间,然后我们可以通过差分来求出每个格子被 ...

  8. Codeforces 1132C - Painting the Fence - [前缀和优化]

    题目链接:https://codeforces.com/contest/1132/problem/C 题意: 栅栏有 $n$ 个节,有 $q$ 个人可以雇佣来涂栅栏,第 $i$ 个人可以涂第 $l_i ...

  9. CodeForces-1132C Painting the Fence

    题目链接 https://vjudge.net/problem/CodeForces-1132C 题面 Description You have a long fence which consists ...

  10. 洛谷——P2205 [USACO13JAN]画栅栏Painting the Fence

    题目描述 Farmer John has devised a brilliant method to paint the long fence next to his barn (think of t ...

随机推荐

  1. Leetcode 153. 寻找旋转排序数组中的最小值

    假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 请找出其中最小的元素. 你可以假设数组中不存在重 ...

  2. mysql关联两张表时的编码问题

    Mysql关联两张表时,产生错误提示Illegal mix of collations 1.先用工具把数据库.两张表的编码方式改变 2.这步很重要,需要改变字段的编码方式. ALTER TABLE ` ...

  3. neo4j 初级使用笔记

    linux下载: curl -O https://neo4j.com/artifact.php?name=neo4j-community-3.5.6-unix.tar.gz 配置端口: baidu h ...

  4. Java连载53-单例模式初步、final关键字补充、回顾知识点

    一.回顾 1.类和对象的区别 2.UML(uniform makeup language) 3.方法区存储静态变量.常量(static final修饰) 4.堆内存中存储对象 5.栈存储变量 6.th ...

  5. python接口自动化7-post文件上传

    前言 文件上传在我们软件是不可少的,最多的使用是体现在我们后台,当然我们前台也会有.但是了解过怎样上传文件吗?这篇我们以禅道文档-创建文档,上传文件为例. post请求中的:Content-Type: ...

  6. Kubernetes容器集群 - harbor仓库高可用集群部署说明

    之前介绍Harbor私有仓库的安装和使用,这里重点说下Harbor高可用集群方案的部署,目前主要有两种主流的Harbor高可用集群方案:1)双主复制:2)多harbor实例共享后端存储. 一.Harb ...

  7. 【MySQL报错】ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

    ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec ...

  8. HTML+css基础 标签

    图片标签:<img src="./imgs/1.jpg" alt=“一种对图片解释说明的” /> HTML   超文本标记语言   英文名称: hyper  text  ...

  9. RadioButtonList

    RadioButtonList <asp:Label ID="txt_Gender" runat="server" Text="性别" ...

  10. 屏幕输入转换为int//方法大注释

    可以使用两种方法: using System; namespace 方法测试 { class Program { static void Main(string[] args) { Console.W ...