题解 [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 ...
随机推荐
- Docker下mysql容器开启binlog日志(保留7天)
现有需求开启用Docker容器启动的mysql数据库的binlog,以作为 日志记录 和 数据恢复,我们了解了MySQL的binlog日志的开启方式以及binlog日志的一些原理和常用操作,我们知道, ...
- Mysql解析json字符串/数组
1 Mysql解析json字符串 解决方法:JSON_EXTRACT(原字段,'$.json字段名') 执行SQL: SELECT JSON_EXTRACT( t.result,'$.row'), ...
- servlet获取checkbox的值出现选中的值为on。问题所在。。。
<form action="/Http/request06" method="post"> 用户名:<input type="tex ...
- 使用haystack实现django全文检索搜索引擎功能
前言 django是python语言的一个web框架,功能强大.配合一些插件可为web网站很方便地添加搜索功能. 搜索引擎使用whoosh,是一个纯python实现的全文搜索引擎,小巧简单. 中文搜索 ...
- mysql replace substring 字符串截取处理
SELECT a1,a2,replace(a2, "豫ICP备16006180号-", "") a22,a3,a4,a5 FROM `aaab` order b ...
- 泛型约束:接口约束、new()构造函数约束、组合约束(即多种约束合并)
泛型 接口约束: using System; namespace ConsoleApp1 { /* * * 接口约束:where T:interfaceName * T是类型形参的名称,interfa ...
- python3.7 lxml4.2.5 etree xpath 的使用
#2019年10月14日11:08:49 from lxml import html etree = html.etree html = etree.HTML(response_dl.content) ...
- Django rest-framework框架-CBV原理
jdango中间件:class Test(View): def dispatch(self, request, *args, **kwargs): #第一种方法 func = getattr(self ...
- Pycharm+Selenium webdriverPython自动化测试
这是关于软件测试的一个作业! 1.Pycharm下载,这里可以自己去官网下载即可:https://www.jetbrains.com/pycharm/download/#section=windows ...
- SpringBoot的启动配置原理
一.启动流程 创建SpringApplication对象 public class SpringApplication { public SpringApplication(Class... prim ...