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 ...
随机推荐
- YII2 blockui
https://packagist.org/packages/ayrozjlc/yii2-blockui
- 【转】oracle回闪操作
在9i上执行的操作 查询test表中记录select * from test;删除test表中记录delete from test;获得过去的会话exec dbms_flashback.disable ...
- windows 精简/封装/部署
给一个精简过的Windows7安装net35,提示自己到『打开或关闭Windows功能』里打开,然而发现并没有,只有一个ie9的功能.搜索尝试各种办法,显然都不行.用dism部署功能的工具,挂载一个完 ...
- SharePoint 2013 网站应用程序、网站集、网站知识整理
网站应用程序:Web 应用程序是一种可以通过Web访问的应用程序.我们自己以前用VS开发的Web应用程序一般是通过人工部署到IIS上的,而SharePoint的Web应用程序是由SharePoint安 ...
- PHP关于依赖注入(控制反转)的解释和例子说明
PHP关于依赖注入(控制反转)的解释和例子说明 发表于2年前(2014-03-20 10:12) 阅读(726) | 评论(1) 8人收藏此文章, 我要收藏 赞2 阿里云双11绽放在即 1111 ...
- mvc3升级mvc4的方法记录.
手工升级ASP.NET MVC 3项目: 一.安装ASP.NET MVC 4 二.升级ASP.NET MVC版本配置信息: 1:替换项目 Web.config 中的 System.Web.Mvc, V ...
- Django model '__week_day'与python datetime的weekday()
上周出了个bug,按星期几查询数据的时候,发现查到的数据与显示的星期几并不相符,后来发现代码中按星期几查询,有的地方用的是Django QuerySet提供的'__week_day',有的地方用的是p ...
- 使用swfupload上传超过30M文件,使用FLASH上传组件
原文:使用swfupload上传超过30M文件,使用FLASH上传组件 前一段时间会员的上传组件改用FLASH的swfupload来上传,既能很友好的显示上传进度,又能完全满足大文件的上传. 后来服务 ...
- JAVA 环境变量设置 (windows + Linux)
注:使用JDK1.5以上的版本,可以不设置CLASSPATH这个环境变量 Windows: 双击安装到某一目录 设置以下环境变量(使用环境变量便于更新) JAVA_HOME E:\software ...
- Maven-007-Nexus 用户添加,用户角色分配,用户修改密码,管理员重置用户密码
配置好 maven nexus 私服后,默认的用户可通过查看[Users]查看当前私服中所存在的用户,如下图所示: