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的更多相关文章

  1. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  2. 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 ...

  3. 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, ...

  4. 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的矩阵中的左下角,放置一个车(车可以移动到同一行或同一列),放置一些墙,竖的占据 ...

  5. 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, ...

  6. Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记

    夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...

  7. [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 ...

  8. Lyft Level 5 Challenge 2018 - Elimination Round

    A. King Escape 签. #include <bits/stdc++.h> using namespace std; ], y[]; int f1(int X, int Y) { ...

  9. Lyft Level 5 Challenge 2018 - Elimination Round翻车记

    打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> ...

随机推荐

  1. ios7注意事项随笔

    1,修改状态栏的样式和隐藏. 首先,需要在Info.plist配置文件中,增加键:UIViewControllerBasedStatusBarAppearance,并设置为YES: 然后,在UIVie ...

  2. Linux+Redis实战教程_day02_3、redis数据类型_4、String命令_5、hash命令_6、java操作redis数据库技术

    3. redis数据类型[重点] redis 使用的是键值对保存数据.(map) key:全部都是字符串 value:有五种数据类型 Key名:自定义,key名不要过长,否则影响使用效率 Key名不要 ...

  3. js中对象的深度复制

    // 对象的深度复制 cloneObj(oldObj) var cloneObj = function (obj) { var newObj = {}; if (obj instanceof Arra ...

  4. Top 20 NuGet packages for captcha

    Top 20 NuGet packages for captcha CaptchaMvc.Mvc4 CaptchaMvc will implement your web MVC application ...

  5. [Command] alias - 别名

    alias 命令可以让用户使用预置的字符串来执行系统命令. 命令是指用户输入指令指示电脑完成工作.命令一般在命令行输入,以回车键完成输入.命令被传递给shell.shell是类Unix操作系统提供的纯 ...

  6. iOS开发——iOS7(及以后版本) SDK自带二维码(含条形码)扫码、二维码生成

    本文转载至 http://www.cnblogs.com/leotangcn/p/4357907.html 现在很多APP都涉及了二维码扫码功能,这个功能简单实用,很多情况下用户乐于使用,现在本文带来 ...

  7. c++学习笔记—单链表基本操作的实现

    用c++语言实现的单链表基本操作,包括单链表的创建(包括头插法和尾插法建表).结点的查找.删除.排序.打印输出.逆置.链表销毁等基本操作. IDE:vs2013 具体实现代码如下: #include  ...

  8. 微信小程序学习指南

    作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  9. IOS设计模式第二篇之单例设计模式

    现在我们的组件已经有组织了.你需要从其他的地方得到数据,你也可以创建一个API类管理数据这个下个设计模式单例里面介绍. 这个单例设计模式确保这个类仅仅拥有一个实例,并且为这个实例提供一个全局的访问点. ...

  10. EGit系列第二篇——关联远程仓库

    网上也有很多代码托管网站支持git,像最出名的GitHub,还有国内支持私有项目的OSC开源中国和CSDN等... 首先得注册个帐号,然后才可以创建仓库 一般都会带一个ReadMe.md,你可以勾选也 ...