题目大意:现在有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. matlab练习程序(计算图像旋转角度)

    比如有图像1,将其旋转n度得到图像2,问如何比较两张图像得到旋转的度数n. 算法思路参考logpolar变换: 1.从图像中心位置向四周引出射线. 2.计算每根射线所打到图像上的像素累计和,得到极坐标 ...

  2. CMake使用总结(一)

    当我们在写CMakeLists.txt文件时,常常会搞不明白link_directories, LINK_LIBRARIES, target_link_libraries这3者的区别,下面就其详细介绍 ...

  3. Jenkins登录后空白页

    进入.jenkins所在的目录 编辑config.xml文件 重启jenkins

  4. CAS单点登录流程图

    1.cas单点登录原理图 2.cas使用代理服务器流程图 3.cas和spring security集成流程图

  5. 第2个word发布的博客

      //接收的为空时,则表示客户端下线,跳出循环 if (r == 0) { break; }; string str = Encoding.UTF8.GetString(buffer, 0, r); ...

  6. File文件的创建,删除 createNewFile() delete()

    package seday03; import java.io.File;import java.io.IOException; /*** 使用File新建一个test1.txt文件* @author ...

  7. 面试官之问:知道你的接口“QPS”是多少吗?

    前言: 原作:孤独烟.因修改不当之处欢迎指出! 大家好,我是小架架. 今天一大早就起来水文章了.这篇文章我个人感觉虽然含金量不是特别大,估计大家大概5分钟左右就能看完!到底是因为什么呢,因为平时干货文 ...

  8. Javase之内部类概述

    内部类概述 把类定义在其他类的内部就称为内部类 class A{ class B{ } } B就称为内部类,A称为外部类. 内部类的访问特点 内部类直接访问外部类成员,包括私有. 外部类要访问内部类要 ...

  9. PLSQL 12 安装、连接Oracle

    点击下载PLSQL,本次安装的PLSQL版本为12.0.7,建议安装64位. 下载PLSQL时,版本旁边会有个“Language pack”的链接,点击后左侧选择“Chinese”即可下载汉化包. 注 ...

  10. 4-1-JS数据类型及相关操作

    js的数据类型 判断数据类型 用typeof   typeof "John"                 // alert(typeof "John") 返 ...