题面

解析

首先贪心地想一想,

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

那到底坐到哪里呢?

考虑先让下面的人先坐,

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

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

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

并且肯定是让刚刚好能坐到这个位置的人坐最好(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. 【转帖】Linux的NUMA机制

    Linux的NUMA机制 http://www.litrin.net/2014/06/18/linux的numa机制/ NUMA(Non-Uniform Memory Access)字面直译为“非一致 ...

  2. Linux基础 目录

    一,linux入门介绍 二,界面目录介绍 三,vim使用 四,文件管理. 文件夹管理. 五.用户创建流程.用户管理 .组管理 六.权限管理.软连接/硬链接 七.磁盘管理 八.软件包的管理 九.系统服务 ...

  3. 汉诺塔递推HDU2064

    题意: 移动木头盘不能a到c,必须a到b到c. 问你移动次数. 假设将n层塔从A经B挪到C需要f[n]步.那么具体的移动过程可以这样看:将上面n-1层从A经B挪到C需要f[n-1]步,再将第n层从A挪 ...

  4. taskverse学习

    简介 taskverse是<linux二进制分析>一书作者编写的一个隐藏进程的检测工具,它使用/proc/kcore来访问内核内存,github的地址在这里:https://github. ...

  5. C#字典转对象

    /// <summary> /// Assign parameters to specified objects /// </summary> /// <typepara ...

  6. Linux上定时shell脚本

    原文链接:http://www.92coder.com/9-Linux%E5%AE%9A%E6%97%B6shell%E8%84%9A%E6%9C%AC/#more 本文主要介绍在Linux系统上部署 ...

  7. springMvc 框架

    第一步:发起请求到前端控制器(DispatcherServlet) 第二步:前端控制器请求HandlerMapping查找 Handler 可以根据xml配置.注解进行查找 第三步:处理器映射器Han ...

  8. gperftools源码分析和项目应用 - CPU Profiler

    gperftools源码分析和项目应用 - CPU Profiler 原文:https://blog.csdn.net/yubo112002/article/details/81076821 原文链接 ...

  9. wepy2创建项目

    1.首先 在桌面(自己选定目录下)新建一个文件夹,注意需要使用英文名. 2.Cmd中  进入到该文件目录下 3.安装 wepy 命令行工具. npm install wepy-cli -g wepy ...

  10. Outline 科学的上网

    outline 官网:https://getoutline.org/zh-CN/home 下载 Outline 管理器 下载 Outline 客户端 配置浏览器代理