题解 [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 ...
随机推荐
- java CGLib代理
转载自 cglib之Enhancer 1. 背景 cglib库的Enhancer在Spring AOP中作为一种生成代理的方式被广泛使用.本文针对Enhancer的用法以实际代码为例作一些介绍. ...
- GCD欧几里得的拓展算法
欧几里得算法的拓展主要是用于求解 : 已知整数 a, b,然后我们进行 ax + by == gcd(a , b) 的问题求解 那么如何进行求解呢?和欧几里得算法一样, 我们需要进行递归的方式进 ...
- spark异常篇-关闭程序
在运行 spark 程序时,出于某种原因,我想停止运行,狂按 ctrl+c 不一定起作用 以下两种情况是不好关闭的 1. cluster 运行模式 2. SparkStreaming 程序 本文旨在收 ...
- 第十章 MIZ702 ZYNQ制作UBOOT固化程序
10.0难度系数★☆☆☆☆☆☆ 10.1是什么是固化 我们前几章将的程序都是通过JTAG先下载bit流文件,再下载elf文件,之后点击Run As来运行的程序.JTAG的方法是通过TCL脚本来初始化P ...
- docker-registry的定制和性能分析
docker-index Web UI Meta-data 元数据存储(附注.星级.公共库清单) 访问认证 token管理 存储镜像.以及镜像层的家族谱系 没有用户账户数据 不知道用户的账户和安全性 ...
- UI自动化的第一步(Python,pip,selenium,PyCharm安装配置)
一,py安装 1.python下载,安装,环境配置 地址:https://www.runoob.com/python/python-install.html 注意:安装时,要勾选自动配置环境变量.这样 ...
- nginx 实践配置
nginx.conf文件 user root; worker_processes 1; error_log logs/error.log crit; #error_log logs/error.log ...
- log4j application.properties 配置文件
log4j.rootLogger = info,stdout log4j.appender.stdout = org.apache.log4j.ConsoleAppenderlog4j.appende ...
- 怎样理解ECMAScript 和 JavaScript的关系
JavaScript可以分为三大部分: 1. 核心语法 2. DOM 3. BOM 而核心语法实际上就是指的ECMAScript, 而JS又是不断在发展的, 而这个发展实际上最主要的就是ECMAScr ...
- Windows编程 Windows程序的生与死(中)
<pre style=""><pre class="cpp" name="code">1 #include < ...