题解 [CF720A] Closing ceremony
解析
首先贪心地想一想,
一个人我们肯定让她坐得尽量远,
那到底坐到哪里呢?
考虑先让下面的人先坐,
那他们就要尽量把离上面入口远的位置坐掉,
因此把位置按离上面的距离从大到小排序,
再一个个看能否被下面的人坐到.
并且肯定是让刚刚好能坐到这个位置的人坐最好(lower_bound一下).
最后把剩下的位置与上面的人一一判断即可.
code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;
inline int read(){
int sum=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return f*sum;
}
const int N=100005;
struct node{int x,y,dis;}p[N],q[N];
int n,m,k,a[N],b[N],ans=1;
int tot,pp,v[N];
multiset <int> s;
bool cmp1(node a,node b){
return a.x+a.y!=b.x+b.y? a.x+a.y>b.x+b.y:a.dis>b.dis;
}
bool cmp(node a,node b){
return a.dis!=b.dis? a.dis>b.dis:a.x+a.y>b.x+b.y;
}
bool cmp2(node a,node b){
return a.dis>b.dis;
}
signed main(){
n=read();m=read();
k=read();
for(int i=1;i<=k;i++) a[i]=read();
int tt=read();
for(int i=1;i<=tt;i++) b[i]=read();
sort(a+1,a+k+1);
sort(b+1,b+tt+1);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
p[++pp].x=i;p[pp].y=j;
p[pp].dis=m+i-j+1;
}
sort(p+1,p+pp+1,cmp);
for(int i=1;i<=k;i++) s.insert(a[i]);
for(int i=1;i<=pp;i++){
int d=p[i].x+p[i].y;
multiset<int>::iterator it=s.lower_bound(d);
if(it!=s.end()) s.erase(it);
else q[++tot]=p[i];
}
if(!s.empty()){puts("NO");return 0;}
pp=0;int tp=1;
for(int i=1;i<=tot;i++) p[++pp]=q[i];
sort(p+1,p+pp+1,cmp2);
for(int i=tt;i>=1;i--){
if(b[i]<p[tp].dis){ans=0;break;}
tp++;
}
puts(ans? "YES":"NO");
return 0;
}
题解 [CF720A] Closing ceremony的更多相关文章
- CF720A Closing ceremony 贪心
正解:贪心 解题报告: 传送门! 先考虑如果只有一列怎么搞?那就肯定是尽量走到最远的地方 然后用点儿类似的思想,现在考虑有两列的情况QAQ 为了方便表述,这里给每个位置两个值,a表示离一号入口的距离, ...
- Codeforces 720A. Closing ceremony
A. Closing ceremony time limit per test 2 seconds memory limit per test 256 megabytes The closing ce ...
- codeforces 720A:Closing ceremony
Description The closing ceremony of Squanch Code Cup is held in the big hall with n × m seats, arran ...
- 退役前的最后的做题记录upd:2019.04.04
考试考到自闭,每天被吊打. 还有几天可能就要AFO了呢... Luogu3602:Koishi Loves Segments 从左向右,每次删除右端点最大的即可. [HEOI2014]南园满地堆轻絮 ...
- Lunch War with the Donkey CSU - 2084
Jingze is a big figure in California State University for his stubbornness. Because of his new failu ...
- 2018SDIBT_国庆个人第二场
A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...
- DP:0
小故事: A * "1+1+1+1+1+1+1+1 =?" * A : "上面等式的值是多少" B : *计算* "8!" A *在上面等式 ...
- 续并查集学习笔记——Closing the farm题解
在很多时候,并查集并不是一个完整的解题方法,而是一种思路. 通过以下题目来体会并查集逆向运用的思想. Description Farmer John and his cows are planning ...
- 【bzoj4579】[Usaco2016 Open]Closing the Farm 并查集
题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to tem ...
随机推荐
- linux 下tomcat出现 Native memory allocation (malloc) failed to allocate 1915224064 bytes for committing reserved memory问题
## There is insufficient memory for the Java Runtime Environment to continue.# Native memory allocat ...
- Kubernetes组件-DaemonSet
⒈简介 Replicationcontroller和ReplicaSet都用于在Kubermetes集群上部署运行特定数量的pod.但是,当某些情况下我们希望在集群中的每个节点上运行同一个指定的pod ...
- git太慢用码云
克隆完之后,我们要对这个仓库进行下修改,将仓库地址修改为git的那个 git remote set-url origin xxxx.git 经过以上操作,这个仓库就和从github上克隆下来的一模一样
- 输入一个正整数n,输出所有和为n的连续正整数序列
public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { System. ...
- tesseract ocr .Net demo
环境vs 2019 .Net 4.8 新建一个wpf工程,拖放上一个button一个textbox nuget下载tesseract,版本信息如图所示 MainWindow.xaml.cs文件代码如下 ...
- Codeforces 1097F. Alex and a TV Show
传送门 由于只要考虑 $\mod 2$ 意义下的答案,所以我们只要维护一堆的 $01$ 容易想到用 $bitset$ 瞎搞...,发现当复杂度 $qv/32$ 是可以过的... 一开始容易想到对每个集 ...
- 关键字:for_each
std::for_each 先贴cppreference中对for_each的概述: template< class InputIt, class UnaryFunction > //此处 ...
- Java学习路径(抛光砖)
这就是我刚刚在五孔问答中找到的Java学习路线图抛光砖价格.我个人认为,这条Java学习路线是可以的.它是2018年相对较新的Java学习路线,更符合企业就业标准. Java学习路径的第一阶段:Jav ...
- ARM与x86 CPU架构对比
CISC(复杂指令集计算机)和RISC(精简指令集计算机)是当前CPU的两种架构.它们的区别在于不同的CPU设计理念和方法.早期的CPU全部是CISC架构,它的设计目的是CISC要用最少的机器语言指令 ...
- 记录lucene.net的使用过程
之前公司要做一个信息展示的网站,领导说要用lucene.net来实现全文检索,类似百度的搜索功能,但是本人技术有限,只是基本实现搜索和高亮功能,特此记录: 先看下页面效果,首先我搜索“为什么APP消息 ...