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 ...
随机推荐
- Centos7下安装Relion
目录 1.Virtual Box 1.1下载Virtual Box 1.2安装Virtual Box 2.Centos7 2.1下载Centos7 2.2安装Centos7 2.2.1配置虚拟机 2. ...
- 【2019.8.20 NOIP模拟赛 T3】小X的图(history)(可持久化并查集)
可持久化并查集 显然是可持久化并查集裸题吧... 就是题面长得有点恶心,被闪指导狂喷. 对于\(K\)操作,直接\(O(1)\)赋值修改. 对于\(R\)操作,并查集上直接连边. 对于\(T\)操作, ...
- "One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?"的解决方法
#事故现场: 在一个.net 4.0 的项目中使用dynamic,示例代码如下: private static void Main(string[] args) { dynamic obj; obj ...
- Groovy元编程应用之自动生成订单搜索接口测试用例集
背景 在 "Groovy元编程简明教程" 一文中,简明地介绍了 Groovy 元编程的特性. 那么,元编程可以应用哪些场合呢?元编程通常可以用来自动生成一些相似的模板代码. 在 & ...
- Caused by: org.springframework.data.mapping.PropertyReferenceException: No property id found for type Users!
Spring Data JPA自定义Repository Caused by: org.springframework.data.mapping.PropertyReferenceException: ...
- c#日期和时间戳互转
using System; using System.Collections.Generic; using System.Data; using System.Reflection; namespac ...
- go-GUI-代码
直接看网址吧,所有的GO-GUI代码!~~~~ 网址
- linux tmux用法
1. 安装工具 Centos : yum install tmux 2. 基本操作 新建会话:tmux new -s session-name 查看会话:tmux ls 进入会话:tmux a -t ...
- AwaitAsync(异步和多线程)
参考了一些大佬写的文章: https://www.cnblogs.com/yilezhu/p/10555849.html这个大佬写的文章,我还是很喜欢的 https://www.cnblogs.com ...
- 采坑 - LODOP,打印预览
结合 layui.弹出框内容样式如下: 红框表示,左右的内边距. 图一 打印预览的样式如下:红框表示,左右的内边距. 图二 要根据图二的左右内边距,去修改图一的左右内边距.不然会影响正文内容高度的判断 ...