codeforces 720A:Closing ceremony
Description
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 l integers 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 正解:贪心
解题报告:
因为我们想使得到两个出发点的距离小,但是不能同时保证两个,那么我们只能先保证一个最优,才想办法判断另外一个。显然把所有点按到左下角距离排序,可以对于左下角的点判断可达,然后我们每次走离左上角尽可能远的点,这样相当于是帮左上角的点分担了一部分远的点,同时可以保证合法性。
//It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int MAXN = ;
int n,m,k,tot;
int a[MAXN];
struct node{
int x,y,z,dis;
bool operator < (const node &a) const{
return a.z>z;
}
}s[MAXN]; priority_queue<node>Q;
inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline bool cmp(node q,node qq){ return q.dis<qq.dis; } inline void work(){
n=getint(); m=getint(); k=getint();
for(int i=;i<=k;i++) a[i]=getint();
sort(a+,a+k+);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
s[++tot].x=i,s[tot].y=j,s[tot].z=m+-j+i,s[tot].dis=i+j;
sort(s+,s+tot+,cmp); int u=; bool ok=true; for(int i=;i<=k;i++) {
while(a[i]>=s[u].dis && u<=tot) Q.push(s[u]),u++;
if(Q.empty()) { ok=false; break; }
Q.pop();//清空
}
if(!ok) { printf("NO"); return; }
while(u<=tot) Q.push(s[u]),u++; k=getint(); for(int i=;i<=k;i++) a[i]=getint();
sort(a+,a+k+);
for(int i=k;i>=;i--) {
if(a[i]<Q.top().z) { ok=false; break; }
Q.pop();
}
if(!ok) { printf("NO"); return; }
printf("YES");
} int main()
{
work();
return ;
}
codeforces 720A:Closing ceremony的更多相关文章
- Codeforces 720A. Closing ceremony
A. Closing ceremony time limit per test 2 seconds memory limit per test 256 megabytes The closing ce ...
- Codeforces 731C:Socks(并查集)
http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问 ...
- Codeforces 747D:Winter Is Coming(贪心)
http://codeforces.com/problemset/problem/747/D 题意:有n天,k次使用冬天轮胎的机会,无限次使用夏天轮胎的机会,如果t<=0必须使用冬轮,其他随意. ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- codeforces 723B:Text Document Analysis
Description Modern text editors usually show some information regarding the document being edited. F ...
- Codeforces 749D:Leaving Auction(set+二分)
http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...
- Codeforces 749B:Parallelogram is Back(计算几何)
http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...
- Codeforces 749C:Voting(暴力模拟)
http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...
- Codeforces 746D:Green and Black Tea(乱搞)
http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设 ...
随机推荐
- 关于tcpdump抓包一个很详细的介绍
http://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html
- lcx转发 【解决内网没法链接3389 的问题】
要求我自己在外网 然后监听1111端口,将1111端口数据流量转发至2222端口 被入侵主机上 将本地的2222端[愿3389 主机修改了远程连接的端口]口流量转发至外网ip的1111端口 2222为 ...
- git review报错一例
在线上修改代码,最后使用git review提交代码审核的时候出现报错如下:[wangshibo@115~]$ vim testfile #修改代码[wangshibo@115~] ...
- 一。常用UIView的属性和方法
1.frame 控件所在的矩形框的位置和尺寸(以父控件的左上角为坐标原点) 2.bounds 控件 控件所在的矩形框的位置和尺寸(以自己的左上角为坐标原点,所以bounds的x/y一般为0) 3.ce ...
- 【转】【C#】ColorMatrix
ColorMatrix(色彩矩阵),是GDI+里用来调整图片色彩的矩阵. 什么是矩阵,说白了就是C#里的二维数组. 那么这个矩阵调整色彩的原理是什么,他是怎么来调整色彩的呢?这个要从线性代数里的矩阵相 ...
- tcpdump参数应用
详细参数: http://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html 我用到的参数: 一 tcpdump重要参数 -i 指定监听 ...
- C++构造函数与析构函数
转自http://blog.csdn.net/tqtuuuu/article/details/6652144 构造函数 对于C++的构造函数,暂且将其分为以下几类: 1. 默认构造函数 2. 隐士转换 ...
- 身份证号码自动生成程序(Python)
今天收到一个小需求:需要一个自动生成身份证号码的小程序.近期用python较多,因此打算用python实现. 需求细化: 1.身份证必须能够通过身份证校验程序. 2.通过查询,发现身份证号码是有国家标 ...
- Linux下高频命令分类辑录(基本使用篇)
本文目的:总结linux下常用命令的基本使用方法 文件权限: 文档权限设置命令:chmod 数字模式: 文档权限由-rwxrwxrwx十个字符组成,其中第一个代表文档类型,后面九个字符按照顺序分为三组 ...
- jquery封装常用方法
var git = { //true表示格式正确 checkEmail: function (str) { -]{,})(\S*)/g) == null) { return false; } else ...