CF-1132 C.Painting the Fence
题目大意:现在有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的更多相关文章
- [luogu P2205] [USACO13JAN]画栅栏Painting the Fence
[luogu P2205] [USACO13JAN]画栅栏Painting the Fence 题目描述 Farmer John has devised a brilliant method to p ...
- 洛谷 画栅栏Painting the Fence 解题报告
P2205 画栅栏Painting the Fence 题目描述 \(Farmer\) \(John\) 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长 ...
- Painting The Fence(贪心+优先队列)
Painting The Fence(贪心+优先队列) 题目大意:给 m 种数字,一共 n 个,从前往后填,相同的数字最多 k 个在一起,输出构造方案,没有则输出"-1". 解题思 ...
- Educational Codeforces Round 61 Editorial--C. Painting the Fence
https://codeforces.com/contest/1132/problem/C 采用逆向思维,要求最大的覆盖,就先求出总的覆盖,然后减去删除两个人贡献最少的人 #include<io ...
- C. Painting the Fence
链接 [https://codeforces.com/contest/1132/problem/C] 题意 就是有个n长的栅栏,然后每个油漆工可以染的区域不同 给你q让你选出q-2个人使得被染色的栅栏 ...
- Painting the Fence Gym - 101911E(构造)
There is a beautiful fence near Monocarp's house. The fence consists of nn planks numbered from left ...
- 【Codeforces 1132C】Painting the Fence
Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数量. 思路:首先枚举第一个删掉的区间,然后我们可以通过差分来求出每个格子被 ...
- Codeforces 1132C - Painting the Fence - [前缀和优化]
题目链接:https://codeforces.com/contest/1132/problem/C 题意: 栅栏有 $n$ 个节,有 $q$ 个人可以雇佣来涂栅栏,第 $i$ 个人可以涂第 $l_i ...
- CodeForces-1132C Painting the Fence
题目链接 https://vjudge.net/problem/CodeForces-1132C 题面 Description You have a long fence which consists ...
- 洛谷——P2205 [USACO13JAN]画栅栏Painting the Fence
题目描述 Farmer John has devised a brilliant method to paint the long fence next to his barn (think of t ...
随机推荐
- As Simple as One and Two
time limit per test3 secondsmemory limit per test256 megabytesinput: standard inputoutput: standard ...
- java非四舍五入
Double htert=34.9768; DecimalFormat df = new DecimalFormat("#.00");// 保留五位小数非四舍五入型 df.setR ...
- zabbix--完整安装攻略
zabbix:是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速定位/解 ...
- 【TCP/IP网络编程】:01理解网络编程和套接字
1.网络编程和套接字 网络编程与C语言中的printf函数和scanf函数以及文件的输入输出类似,本质上也是一种基于I/O的编程方法.之所以这么说,是因为网络编程大多是基于套接字(socket,网络数 ...
- 配置vtk(Win8.1 + VS2012+VTK-5.10.1)
1.下载相关软件 vtk-5.10.1.zip和vtkdata-5.10.1.zip http://www.vtk.org/files/release/5.10/vtk-5.10.1.zip http ...
- 前端笔记之Vue(四)UI组件库&Vuex&虚拟服务器初识
一.日历组件 new Date()的月份是从0开始的. 下面表达式是:2018年6月1日 new Date(2018, 5, 1); 下面表达式是:2018年5月1日 new Date(2018, 4 ...
- struts2文件上传报错
说明上传的文件为空,检查上传文件名
- PHP fastcgi_finish_request 方法
本文介绍,PHP运行在FastCGI模式时,FPM提供的方法:fastcgi_finish_request. 在说这个方法之前,我们先了解PHP有哪些常用的运行模式? PHP运行模式 CGI 通用网关 ...
- 前端框架Easyui学习积累
前端框架Easyui学习积累 1.easyui textbox 赋值:$("#id").textbox("setValue","xx"); ...
- Redisson实现分布式锁(2)—RedissonLock
Redisson实现分布式锁(2)-RedissonLock 有关Redisson实现分布式锁上一篇博客讲了分布式的锁原理:Redisson实现分布式锁---原理 这篇主要讲RedissonLock和 ...