Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)---ABC
A---The King's Race
http://codeforces.com/contest/1075/problem/A
题意:
一个人在\((1,1)\), 一个人在\((n,n)\), 现在他们每次轮流走一步,问谁先到达\((x,y)\)
思路:
每个人走到\((x,y)\)的步数是可以直接求出的。
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; LL n;
LL x, y; int main()
{
while(scanf("%I64d", &n) != EOF){
scanf("%I64d%I64d", &x, &y);
LL mvwhite, mvblack;
mvwhite = x - + y - ;
mvblack = n - x + n - y; if(mvwhite <= mvblack){
printf("White\n");
}
else{
printf("Black\n");
}
}
return ;
}
B---Taxi drivers and Lyft
http://codeforces.com/contest/1075/problem/B
题意:
一条线上有住户和出租车司机,给定他们家的横坐标和他们的身份。一个出租车司机会接到离他家最近的所有客人,如果两个出租车司机一样近,这个客人会给横坐标小的司机。现在问所有出租车司机的客人分别是多少。
思路:
从左到右找到每个住户左边最近的出租车司机,从右到左找到每个住户右边最近的出租车司机。
对每个住户判断一下他属于哪一个出租车司机。
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <vector>
#include <map>
#include <set>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int n, m;
const int maxn = 2e5 + ;
int house[maxn];
int taxi[maxn];
int lft[maxn], rig[maxn];
int cnt[maxn]; int main()
{
while(scanf("%d%d", &n, &m) != EOF){
for(int i = ; i < n + m; i++){
scanf("%d", &house[i]);
cnt[i] = ;
}
for(int i = ; i < n + m; i++){
scanf("%d", &taxi[i]);
} int last = -;
for(int i = ; i < n + m; i++){
if(taxi[i]){
last = i;
}
else{
lft[i] = last;
}
}
last = -;
for(int i = n + m - ; i >= ; i--){
if(taxi[i]){
last = i;
}
else{
rig[i] = last;
}
} for(int i = ; i < n + m; i++){
if(!taxi[i]){
//cout<<lft[i]<<" "<<rig[i]<<endl;
if(lft[i] == -){
cnt[rig[i]]++;
}
else if(rig[i] == -){
cnt[lft[i]]++;
}
else{
if(house[i] - house[lft[i]] <= house[rig[i]] - house[i]){
cnt[lft[i]]++;
}
else{
cnt[rig[i]]++;
}
}
}
} bool flag = false;
for(int i = ; i < n + m; i++){
if(taxi[i]){
if(flag)printf(" ");
else{
flag = true;
}
printf("%d", cnt[i]);
}
}
printf("\n");
}
return ;
}
C---The Tower is Going Home
http://codeforces.com/contest/1075/problem/C
题意:
在\((1,1)\)位置有一个象棋子。现在他要走到行数是1e9的位子。整个棋盘大小是1e9 * 1e9.棋盘中有一些横线和竖线的墙,问最少删去多少条可以让他走到行数是1e9的地方。
思路:
首先我们可以发现水平的墙中,如果他不是从1开始的,这个水平的墙就是没有用的。就不用存了。
然后对水平的墙按照x2排序,对竖直的墙也排序。
每次我们枚举要删去的竖直的墙。如果\(i\)要删去,那么\(1~i-1\)肯定也要删去。
然后我们统计一下删去了前\(i\)面墙之后,横着的墙里面有多少个和后面的竖着的墙有交点,有交点的这些横着的墙也是要删去的。
因为每次从左到右遍历竖着的墙的时候,被删去的横着的墙数应该是减少的。所以只用存一个变量来记录就可以了,不用每次都循环去找。
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <vector>
#include <map>
#include <set>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int n, m;
const int maxn = 1e5 + ;
struct horizontal{
int x1, x2, y;
}h_spell[maxn];
int tot;
int v_spell[maxn]; bool cmp_h(horizontal a, horizontal b)
{
return a.x2 < b.x2;
} int main()
{
while(scanf("%d%d", &n, &m) != EOF){
tot = ;
for(int i = ; i <= n; i++){
scanf("%d", &v_spell[i]);
}
v_spell[n + ] = 1e9;
sort(v_spell + , v_spell + n + ); for(int i = ; i < m; i++){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if(a == ){
h_spell[++tot].x1 = a;
h_spell[tot].x2 = b;
h_spell[tot].y = c;
}
}
sort(h_spell + , h_spell + tot + , cmp_h); int id_h = , ans = n + m, cnt = tot;
for(int i = ; i <= n + ; i++){
while(id_h < tot && h_spell[id_h + ].x2 < v_spell[i]){
id_h++;
cnt--;
}
ans = min(ans, cnt + i - );
} printf("%d\n", ans);
}
return ;
}
Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)---ABC的更多相关文章
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)
B. Taxi drivers and Lyft time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)
A. The King's Race 签. #include <bits/stdc++.h> using namespace std; #define ll long long ll n, ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) C. The Tower is Going Home(思维+双指针)
https://codeforces.com/contest/1075/problem/C 题意 一个宽为1e9*1e9的矩阵中的左下角,放置一个车(车可以移动到同一行或同一列),放置一些墙,竖的占据 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) A. The King's Race
http://codeforces.com/contest/1075/problem/A On a chessboard with a width of nn and a height of nn, ...
- Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记
夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
- [Lyft Level 5 Challenge 2018 - Elimination Round][Codeforces 1033D. Divisors]
题目链接:1033D - Divisors 题目大意:给定\(n\)个数\(a_i\),每个数的约数个数为3到5个,求\(\prod_{i=1}^{n}a_i\)的约数个数.其中\(1 \leq n ...
- Lyft Level 5 Challenge 2018 - Elimination Round
A. King Escape 签. #include <bits/stdc++.h> using namespace std; ], y[]; int f1(int X, int Y) { ...
- Lyft Level 5 Challenge 2018 - Elimination Round翻车记
打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> ...
随机推荐
- Java并发:多线程和java.util.concurrent并发包总结
多线程和java.util.concurrent并发包 转载:
- maven的多环境配置
<profiles> <profile> <id>dev</id> <activation> <activeByDefault> ...
- c# windows服务
参考:https://www.cnblogs.com/knowledgesea/p/3616127.html 序言 前段时间做一个数据迁移项目,刚开始用B/S架构做的项目,但B/S要寄存在IIs中,而 ...
- SpringMVC由浅入深day01_2springmvc入门程序
2 入门程序 2.1 需求 以案例作为驱动. springmvc和mybaits使用一个案例(商品订单管理). 功能需求:商品列表查询 2.2 环境准备 数据库环境:mysql5.5 先导入sql_t ...
- 03-Linux各目录及每个目录的详细介绍
Linux各目录及每个目录的详细介绍 [常见目录说明] 目录 /bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里. /etc 存放系统管理和配置文件 /home 存放所 ...
- SSL延迟有多大 (Https)
据说,Netscape公司当年设计SSL协议的时候,有人提过,将互联网所有链接都变成HTTPs开头的加密链接. 这个建议没有得到采纳,原因之一是HTTPs链接比不加密的HTTP链接慢很多.(另一个原因 ...
- 关于MySQL数据库
MySQL最流行的关系型数据库管理系统 MySQL官网:http://www.mysql.com MySQL是WEB应用方面最好的RDBMS应用软件之一 RDBMS:Relational Databa ...
- 【NGINX】Windows配置
缺省安装nginx之后的配置 检查80端口占用 启动缺省配置之后的nginx 配置多端口站点 注册Server,server_name是配置的域名,proxy_pass是上图配置的代理地址 注意: 1 ...
- Myecplise反编译工具安装
我使用的是Myecplise8.5 下载jad.exe文件jad158g.win.zip:http://varaneckas.com/jad/ 下载jadeclipse插件 net.sf.jadcli ...
- DOM的学习
今天学习了DOM,感觉学习起来真的没那么简单啦,这不是一个好现象啊,只有依靠自己大补课,嘿嘿,具体的总结了一下,今天学习的其实并不多,仅仅学习了不同的节点类型,但是知识还是蛮碎的,要一点一点的总结,昨 ...