题面

解析

首先贪心地想一想,

一个人我们肯定让她坐得尽量远,

那到底坐到哪里呢?

考虑先让下面的人先坐,

那他们就要尽量把离上面入口远的位置坐掉,

因此把位置按离上面的距离从大到小排序,

再一个个看能否被下面的人坐到.

并且肯定是让刚刚好能坐到这个位置的人坐最好(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的更多相关文章

  1. CF720A Closing ceremony 贪心

    正解:贪心 解题报告: 传送门! 先考虑如果只有一列怎么搞?那就肯定是尽量走到最远的地方 然后用点儿类似的思想,现在考虑有两列的情况QAQ 为了方便表述,这里给每个位置两个值,a表示离一号入口的距离, ...

  2. Codeforces 720A. Closing ceremony

    A. Closing ceremony time limit per test 2 seconds memory limit per test 256 megabytes The closing ce ...

  3. codeforces 720A:Closing ceremony

    Description The closing ceremony of Squanch Code Cup is held in the big hall with n × m seats, arran ...

  4. 退役前的最后的做题记录upd:2019.04.04

    考试考到自闭,每天被吊打. 还有几天可能就要AFO了呢... Luogu3602:Koishi Loves Segments 从左向右,每次删除右端点最大的即可. [HEOI2014]南园满地堆轻絮 ...

  5. Lunch War with the Donkey CSU - 2084

    Jingze is a big figure in California State University for his stubbornness. Because of his new failu ...

  6. 2018SDIBT_国庆个人第二场

    A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...

  7. DP:0

    小故事: A * "1+1+1+1+1+1+1+1 =?" * A : "上面等式的值是多少" B : *计算* "8!" A *在上面等式 ...

  8. 续并查集学习笔记——Closing the farm题解

    在很多时候,并查集并不是一个完整的解题方法,而是一种思路. 通过以下题目来体会并查集逆向运用的思想. Description Farmer John and his cows are planning ...

  9. 【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 ...

随机推荐

  1. 自然语言处理工具HanLP-基于层叠HMM地名识别

    本篇接上一篇内容<HanLP-基于HMM-Viterbi的人名识别原理介绍>介绍一下层叠隐马的原理. 首先说一下上一篇介绍的人名识别效果对比: 1. 只有Jieba识别出的人名 准确率极低 ...

  2. go 二进制数据处理

    以下是利用标准库binary来进行编解码 编码 ①使用bytes.Buffer来存储编码生成的串②使用binary.Write来编码存储在①的buf中 package main import ( &q ...

  3. TP5.1框架中的模型关联

    一对一关联 hasOne('关联模型','外键','主键'); 关联模型(必须):关联的模型名或者类名 外键:默认的外键规则是当前模型名(不含命名空间,下同)+_id ,例如user_id 主键:当前 ...

  4. Springboot项目自动加载设置

    SpringBoot是允许项目自动加载的,但是需要在pom文件映入依赖库 1.导入依赖库 <dependency> <groupId>org.springframework.b ...

  5. LeetCode. 矩阵中的最长递增路径

    题目要求: 给定一个整数矩阵,找出最长递增路径的长度. 对于每个单元格,你可以往上,下,左,右四个方向移动. 你不能在对角线方向上移动或移动到边界外(即不允许环绕). 示例: 输入: nums = [ ...

  6. npm—入门指导

    npm npm是什么? NPM(node package manager),通常称为node包管理器.顾名思义,它的主要功能就是管理node包,包括:安装.卸载.更新.查看.搜索.发布等. npm的背 ...

  7. 【Python基础】11_Python中的字符串

    1.字符串的定义 可以使用""双引号,也可以使用''单引号定义字符串,一般使用双引号定义. 2.字符串的操作 判断类型: 查找和替换 大小写切换: 文本对齐 注:string.ce ...

  8. 【第一季】CH06_FPGA设计Verilog基础(三)

    [第一季]CH06_FPGA设计Verilog基础(三) 一个完整的设计,除了好的功能描述代码,对于程序的仿真验证是必不可少的.学会如何去验证自己所写的程序,即如何调试自己的程序是一件非常重要的事情. ...

  9. Lua模除运算的大坑

    问题 对负数进行模除运算遇到的坑,Lua的%运算与C++的%有差异 实践 结论 Lua%运算的基本公式 a % b = a - ( ( a // b ) * b ) 1.在C,C++中 %运算符的取整 ...

  10. 怎样设置Cookie

    因为 Cookie 是服务器保存在浏览器中的一小段信息, 因此这个设置应当是服务器发起的, 设置方法是在Response Header中添加: Set-Cookie字段, 值是多个键值对. 如下: / ...