题目大意:现在有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. Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

    docker pull nginx 遇到这个问题 Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: ...

  2. 基础知识 Asp.Net MVC EF各版本区别

    原文:https://www.cnblogs.com/liangxiaofeng/p/5840754.html 2009年發行ASP.NET MVC 1.0版 2010年發行ASP.NET MVC 2 ...

  3. C语言验证哥德巴赫猜想

    #include<stdio.h>int f(int x);int main(void){    int n,i;  scanf("%d",&n);  for( ...

  4. C# Event在.Net规则下由接口定义的实现

    最近在学C#(教材<C# in a nutshell>很不错的说),看完delegate(委托)以后,紧接着就是event(事件)了,个人对跟.Net相关的东西并没有什么兴趣(毕竟是会增加 ...

  5. 拎壶带你冲----教育类mysql用户表设计参考

    说起用户表,大概是每个应用/网站立项动工(码农们)考虑的第一件事情.用户表结构的设计,算是整个后台架构的基石.如果基石不稳,待到后面需求跟进了发现不能应付,回过头来反复修改用户表,要大大小小作改动的地 ...

  6. 在 ASP.NET Core 中使用 ApplicationPart 的简单示例

    1. 项目截图: 2. 代码 <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFra ...

  7. 数据库——SQL-SERVER练习(6) 数据库安全性

    一.实验准备 (1)运行SQL-SERVER服务管理器, 启动服务(2)运行查询分析器,  以DBA身份登录数据库服务器:      用户名sa,  密码123456(3)打开CREATE-TABLE ...

  8. PHP odbc_errormsg ODBC 函数

    定义和用法 odbc_errormsg - 获取最后一条错误消息 语法 odbc_errormsg ( [ resource $connection_id ] ) 返回包含最后一个ODBC错误消息的字 ...

  9. iOS中的NSOperation线程

    1.除NSThread之外的第二种多线程的编程方法   2.采用NSOperation(线程操作,通常用他的子类)和NSOperationQueue(线程队列)搭配来做多线程开发,采用NSOperat ...

  10. rocksdb和leveldb的bloom filter比较

    memtable中的bloom filter rocksdb在memtable中添加了prefix bloom filter,就是对key取prefix,然后把这个prefix加入到bloom fil ...