Codeforces 720A. Closing ceremony
2 seconds
256 megabytes
The closing ceremony of Squanch Code Cup is held in the big hall with n × m seats, arranged in n rows, m seats in a row. Each seat has two coordinates (x, y) (1 ≤ x ≤ n, 1 ≤ y ≤ m).
There are two queues of people waiting to enter the hall: k people are standing at (0, 0) and n·m - k people are standing at (0, m + 1). Each person should have a ticket for a specific seat. If person p at (x, y) has ticket for seat (xp, yp) then he should walk |x - xp| + |y - yp|to get to his seat.
Each person has a stamina — the maximum distance, that the person agrees to walk. You should find out if this is possible to distribute all n·m tickets in such a way that each person has enough stamina to get to their seat.
The first line of input contains two integers n and m (1 ≤ n·m ≤ 104) — the size of the hall.
The second line contains several integers. The first integer k (0 ≤ k ≤ n·m) — the number of people at (0, 0). The following k integers indicate stamina of each person there.
The third line also contains several integers. The first integer l (l = n·m - k) — the number of people at (0, m + 1). The following lintegers indicate stamina of each person there.
The stamina of the person is a positive integer less that or equal to n + m.
If it is possible to distribute tickets between people in the described manner print "YES", otherwise print "NO".
2 2
3 3 3 2
1 3
YES
2 2
3 2 3 3
1 2
NO
题目大意:n*m个座位, 有n*m个人,一开始有k个人在(0,0)点上,l个人在(0,m+1)点上,每个人有对应的体力值,体力值即为可以行走的距离(曼哈顿距离),问是否存在一种方案是每个人花费的体力不超过上限,且每个人都有位置坐。
贪心:对于前k个人,我们按照体力排序,显然找到一个以距离(0,m+1)尽可能远为第一关键字,与(0,0)尽可能远为第二关键字的位置,那么这个人就应该在这个位置。之后l个人放到与(0,m+1)尽可能远的且没有人的位置,检测是否存在这种可能。
AC code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
#include<ctime>
#include<cstring>
#define yyj(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout);
#define llg long long
#define maxn 10010
using namespace std;
llg i,j,k,n,m,k1,k2,t1,t2,bj[maxn],x,y,l,len,a[maxn],b[maxn],maxl;
bool f;
int main()
{
yyj("");
cin>>n>>m>>k1;
for (i=;i<=k1;i++) cin>>a[i];
sort(a+,a+k1+);
cin>>k2;
for (j=;j<=k2;j++) cin>>b[j];
sort(b+,b+k2+);
int c[n+][m+];
for (i=;i<=n;i++) for (j=;j<=m;j++) c[i][j]=;
for (k=;k<=k1;k++)
{
f=false; maxl=;
for (i=;i<=n;i++)
for (j=;j<=m;j++)
if (i+j<=a[k] && i+m+-j>maxl && c[i][j]==)
{
f=true;
x=i,y=j;
maxl=i+m-j+;
}
if (f)
{
c[x][y]=;
}
else
{
cout<<"NO";
return ;
}
}
for (k=;k<=k2;k++)
{
maxl=,f=false;
for (i=;i<=n;i++)
for (j=;j<=m;j++)
if (c[i][j]== && i+m+-j>maxl && i+m+-j<=b[k])
{
f=true;
x=i; y=j;
maxl=i+m+-j;
}
if (f)
{
c[x][y]=;
}
else
{
cout<<"NO";
return ;
}
}
cout<<"YES";
return ;
}
Codeforces 720A. Closing ceremony的更多相关文章
- codeforces 720A:Closing ceremony
Description The closing ceremony of Squanch Code Cup is held in the big hall with n × m seats, arran ...
- CF720A Closing ceremony 贪心
正解:贪心 解题报告: 传送门! 先考虑如果只有一列怎么搞?那就肯定是尽量走到最远的地方 然后用点儿类似的思想,现在考虑有两列的情况QAQ 为了方便表述,这里给每个位置两个值,a表示离一号入口的距离, ...
- 题解 [CF720A] Closing ceremony
题面 解析 首先贪心地想一想, 一个人我们肯定让她坐得尽量远, 那到底坐到哪里呢? 考虑先让下面的人先坐, 那他们就要尽量把离上面入口远的位置坐掉, 因此把位置按离上面的距离从大到小排序, 再一个个看 ...
- 退役前的最后的做题记录upd:2019.04.04
考试考到自闭,每天被吊打. 还有几天可能就要AFO了呢... Luogu3602:Koishi Loves Segments 从左向右,每次删除右端点最大的即可. [HEOI2014]南园满地堆轻絮 ...
- 2018SDIBT_国庆个人第二场
A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...
- Lunch War with the Donkey CSU - 2084
Jingze is a big figure in California State University for his stubbornness. Because of his new failu ...
- DP:0
小故事: A * "1+1+1+1+1+1+1+1 =?" * A : "上面等式的值是多少" B : *计算* "8!" A *在上面等式 ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)
A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...
- Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence 栈
C. Replace To Make Regular Bracket Sequence 题目连接: http://www.codeforces.com/contest/612/problem/C De ...
随机推荐
- 【iCore3 双核心板】例程三十:U_DISK_IAP_FPGA实验——更新升级FPGA
实验指导书及代码包下载: http://pan.baidu.com/s/1jH1TiKY iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- zepto源码--核心方法8(管理包装集)--学习笔记
继续包装集过滤的相关函数的介绍,今天介绍与父元素相关的函数,parent, parents, closest, offsetParent parent 获取对象集合中每个元素的直接父元素. 与上篇文章 ...
- fuelux.tree用法
ACE中带了一个树,样式和操作挺好看的,就是难用,下面记录下如何使用. 首先fuelux.tree接受的数据源是Json,关键这个Json还不怎么标准,可接受的Json示例如下: { '刑侦': { ...
- js-方法
最近觉得自己的基础貌似太薄弱了,找了几本电子书,整理了一下基础的 方法: Concat:返回一个新数组 var a=['a','b','c']; var b=['x','y','z']; var c= ...
- thinkphp的钩子的两种配置和两种调用方法
thinkphp的钩子行为类是一个比较难以理解的问题,网上有很多写thinkphp钩子类的文章,我也是根据网上的文章来设置thinkphp的钩子行为的,但根据这些网上的文章,我在设置的过程中,尝试了十 ...
- SQL Server 索引中include的魅力(具有包含性列的索引)
2010-01-11 20:44 by 听风吹雨, 22580 阅读, 24 评论, 收藏, 编辑 开文之前首先要讲讲几个概念 [覆盖查询] 当索引包含查询引用的所有列时,它通常称为“覆盖查询”. [ ...
- Hadoop学习笔记: 全排序
在Hadoop中实现全排序有如下三种方法: 1. 只使用一个reducer 2. 自定义partitioner 3. 使用TotalOrderPartitioner 其中第一种方法显然违背了mapre ...
- erlang httpc
1,set proxy 10.100.1.76 :8888 httpc:set_options([{proxy,{{"10.100.1.76",8888},[]}}]). 2,se ...
- 20145320《Java程序设计》第三次实验报告
20145320<Java程序设计>第三次实验报告 北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1453 指导教师:娄嘉鹏 实验日期:2016.04.22 15: ...
- sp_executesql
execute相信大家都用的用熟了,简写为exec,除了用来执行存储过程,一般都用来执行动态Sql sp_executesql,sql2005中引入的新的系统存储过程,也是用来处理动态sql的, 如 ...