Lyft Level 5 Challenge 2018 - Elimination Round

【CodeForces】Lyft Level 5 Challenge 2018 - Elimination Round (Div. 1 + Div. 2) 题解 【比赛链接】 点击打开连接 【题解链接】 点击打开链接 **【A】**King Escape 【思路要点】 皇后会攻击到 888 条直线,其中 444 条斜向的可以跨过,因此可以忽略。 判断起始点和目标点是否在其余 444 条线分割出的同一个联通块内即可。 时间复杂度 O(1)O(1)O(1) 。 【代码】 #include<bits/stdc++.h> us... 阅读详情

                                                                             A. King Escape

Alice and Bob are playing chess on a huge chessboard with dimensions n×nn×n. Alice has a single piece left — a queen, located at (ax,ay)(ax,ay), while Bob has only the king standing at (bx,by)(bx,by). Alice thinks that as her queen is dominating the chessboard, victory is hers.

But Bob has made a devious plan to seize the victory for himself — he needs to march his king to (cx,cy)(cx,cy) in order to claim the victory for himself. As Alice is distracted by her sense of superiority, she no longer moves any pieces around, and it is only Bob who makes any turns.

Bob will win if he can move his king from (bx,by)(bx,by) to (cx,cy)(cx,cy) without ever getting in check. Remember that a king can move to any of the 88 adjacent squares. A king is in check if it is on the same rank (i.e. row), file (i.e. column), or diagonal as the enemy queen.

Find whether Bob can win or not.

Input

The first line contains a single integer nn (3≤n≤10003≤n≤1000) — the dimensions of the chessboard.

The second line contains two integers axax and ayay (1≤ax,ay≤n1≤ax,ay≤n) — the coordinates of Alice's queen.

The third line contains two integers bxbx and byby (1≤bx,by≤n1≤bx,by≤n) — the coordinates of Bob's king.

The fourth line contains two integers cxcx and cycy (1≤cx,cy≤n1≤cx,cy≤n) — the coordinates of the location that Bob wants to get to.

It is guaranteed that Bob's king is currently not in check and the target location is not in check either.

Furthermore, the king is not located on the same square as the queen (i.e. ax≠bxax≠bx or ay≠byay≠by), and the target does coincide neither with the queen's position (i.e. cx≠axcx≠ax or cy≠aycy≠ay) nor with the king's position (i.e. cx≠bxcx≠bx or cy≠bycy≠by).

Output

Print "YES" (without quotes) if Bob can get from (bx,by)(bx,by) to (cx,cy)(cx,cy) without ever getting in check, otherwise print "NO".

You can print each letter in any case (upper or lower).

Examples

input

Copy

8
4 4
1 3
3 1

output

Copy

YES

input

Copy

8
4 4
2 3
1 6

output

Copy

NO

input

Copy

8
3 5
1 2
6 1

output

Copy

NO

Note

In the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue.

In the first case, the king can move, for instance, via the squares (2,3)(2,3) and (3,2)(3,2). Note that the direct route through (2,2)(2,2) goes through check.

In the second case, the queen watches the fourth rank, and the king has no means of crossing it.

In the third case, the queen watches the third file.

 

题意就是在国王移动的时候,x轴和y轴不能与女王的x轴和y轴相等

 

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int n;
	while (cin >> n) {
		int x1, y1; cin >> x1 >> y1;
		int x2, y2; cin >> x2 >> y2;
		int x3, y3; cin >> x3 >> y3;
		int flag = 0;
		if (x2 > x3) swap(x2, x3);
		for (int i = x2;i <= x3;i++) {
			if (i == x1) flag = 1;
		}
		if (y2 > y3) swap(y2, y3);
		for (int i = y2;i <= y3;i++) {
			if (i == y1) flag = 1;
		}
		if (flag) puts("NO");
		else puts("YES");
	}
	return 0;
}

 

 

 

                                                                     B. Square Difference

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Alice has a lovely piece of cloth. It has the shape of a square with a side of length aa centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length bb centimeters (where b<ab<a). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).

Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?

Input

The first line contains a number tt (1≤t≤51≤t≤5) — the number of test cases.

Each of the next tt lines describes the ii-th test case. It contains two integers aa and b (1≤b<a≤1011)b (1≤b<a≤1011) — the side length of Alice's square and the side length of the square that Bob wants.

Output

Print tt lines, where the ii-th line is the answer to the ii-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO".

You can print each letter in an arbitrary case (upper or lower).

Example

input

Copy

4
6 5
16 13
61690850361 24777622630
34 33

output

Copy

YES
NO
NO
YES

Note

The figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is 62−52=36−25=1162−52=36−25=11, which is prime, so the answer is "YES".

In the second case, the area is 162−132=87162−132=87, which is divisible by 33.

In the third case, the area of the remaining piece is 616908503612−247776226302=3191830435068605713421616908503612−247776226302=3191830435068605713421. This number is not prime because 3191830435068605713421=36913227731⋅864684729913191830435068605713421=36913227731⋅86468472991.

In the last case, the area is 342−332=67342−332=67.

 

题意:

就是从一个大的正方形取一个小的正方形,剩下的面积是一个质数

 

理解:考察质数的应用 

定理:

质数乘质数等于合数

合数:

合数,指自然数中除了能被1和本身整除外,还能被其他数(0除外)整除的数。与之相对的是质数(因数只有1和它本身,如2,3,5,7,11,13等等,也称素数),而1既不属于质数也不属于合数。

任何一个合数,都可以写成两个或者两个以上的质数相乘的形式

 

对于 a^2-b^2=(a+b)(a-b),  那么就可以知道如果这个是一个质数那么只能其一个是质数  所以 a-b  为1

#include<bits/stdc++.h>
using namespace std;

typedef long long int LL;
bool isprime(LL x)
{
	if(x==1) return false;
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0) return false;
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;
	for(cin>>T;T--;){
		LL a,b;
		cin>>a>>b;
		if(isprime(a+b)&&(a-b==1)) cout<<"YES"<<'\n';
		else cout<<"NO"<<'\n'; 
	}
	return 0;
}

 

基于arduino开发环境 esp32开发板 L298N电机驱动的双驱蓝牙小车教程(零基础版) 基于ardino开发环境 esp32开发板 L298N电机驱动的双驱蓝牙小车教程(零基础版) 阅读详情

相关推荐

halcon C++编程 第4讲 HObject/HImage Mat相互转换(tcy)

网上有很多相互转换程序,但并不知那个正确,本文对相互转换后的结果和原对象比较是否相同判断转换是否正确。经测试ok.本文包括转换代码及测试是否相同。 1.转换程序: /************************************ HObject转为Mat:time:2021/3/16 V1.0 *************************************/ cv::Mat HalconClass::HObjectToMat(const HalconCpp::HObject&..

tcy-阿春 4943

Lyft Level 5 Challenge 2018 - Elimination Round A. King Escape

BFS练手题目

weixin_66382718的博客 177

高通AI Engine SDK(QNN)使用教程(环境配置、模型转换、量化、推理、分析)

高通AI Engine使用教程

weixin_51031772的博客 1万+

Lyft Level 5 Challenge 2018 - Elimination Round 题解

A题: 女王棋子将棋盘划分为四个象限,判断两个棋子的坐标是否在同一象限即可 #include&lt;stdio.h&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;cmath&gt; #include&lt;cstring&gt; #include&lt;queue&gt; #include&lt;stac...

c3po 312

路径跟踪 | 图解路径跟踪PID算法(附ROS C++/Python/Matlab仿真)

PID控制是一种经典的控制算法,广泛应用于各种工业场景。在基于PID的局部路径规划中,希望机器人能快速跟踪上预设的轨迹。本文介绍PID控制的基本原理,并基于PID控制律设计路径跟踪算法,最后通过ROS C++/Python/Matlab进行仿真实现,加深理解

FRIGIDWINTER的博客 1万+

基于STM32F103C8T6的智能蓝牙手环系统设计与实现

摘要:本文设计并实现了一款基于STM32F103C8T6单片机的智能蓝牙手环系统。该系统集成了ADXL345加速度计、DS18B20温度传感器、plusesennor心率模块和BT06蓝牙模块,实现了心率(±2bpm)、体温(±0.5℃)、步数(±3%)等健康数据的实时监测与显示。通过OLED屏提供人机交互界面,支持蓝牙APP远程控制,具备自动步数清零、异常提醒等功能。测试表明系统各项功能均达到设计要求,响应时间0.1-0.5秒,心率检测准确率98%,体温检测准确率99%,功耗50mA(工作)/10mA(待

3254968421的博客 218

Lyft Level 5 Challenge 2018 - Elimination Round D

题目大意是给你n个数,然后让你把n个数相乘,求乘积约数的个数,a[i]&lt;=2e18。题目保证每个a[i]的约数在3到5个之间。这个条件很有用,因为一个数的约数最少为2个,1和它本身,所以可能情况只有4种pq,p的平方,p的三次方,p的四次方。后三个直接套就可以,第一个我们需要特殊处理一下,因为这种情况肯定是两个质数相乘,我们需要先判断p或q是否在其他a[j]中出现过,如果出现过,我们直接把p...

yqdjl6的博客 331

十九、帧间预测编码_2、解码、显示顺序与图像管理、参考帧管理

一、基本概念 1.1H.264的解码顺序和显示顺序: 解码过程中,每一帧的数据按照相应的NAL Unit在码流中的顺序传入解码器进行解码 由于B帧的存在,视频帧在输出时会进行顺序重排 1.2frame_num与POC frame_num:表示解码顺序 POC:表示显示顺序(picture_order_count) 在H.264的码流中,表示解码顺序和显示顺序分别有相应的语法元素表示。这两个值都会在码流中保存,并在读取slice信息时解析(SliceHeader中) 1.3参考帧列表 某一帧图像在解

叮咚的博客 1335

CF1033A. King Escape的题解

题目链接:http://codeforces.com/problemset/problem/1033/A Problem Description Alice and Bob are playing chess on a huge chessboard with dimensionsn×nn×n. Alice has a single piece left— a queen, locat...

weixin_30239339的博客 307

跨应用服务器的自定义 IDoc 传输实战:以 CATSDB 工时为例,打通两套 SAP 系统的数据通道

本文介绍了在企业多SAP系统环境下,使用SAP ALE/IDoc技术实现工时数据跨系统传输的解决方案。文章从技术选型、系统架构到具体配置步骤进行了详细说明,重点阐述了IDoc/ALE在异步传输、全链路追踪和数据重放方面的优势。 文章详细讲解了端到端实施流程,包括Logical System配置、RFC Destination创建、Message Type定义、Segment和Basic Type设计等关键步骤。同时提供了出站封装的ABAP代码示例,强调调用MASTER_IDOC_DISTRIBUTE函数后执

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 179

RT-DERT安卓部署教程

这个文档中的代码案例,实现了拍照和选图识别,两个功能,可以看效果图。UI做了美化:显示类别机和数量。代码下载地址:通过网盘分享的文件:android_rtdert.zip链接: https://pan.baidu.com/s/1k6e-d_lov1OPgUmit5i_cA?pwd=hpfi 提取码: hpfi–来自百度网盘超级会员v8的分享。

AIOT魔法师 199

[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 \leq 500 , 1 \leq a_i \leq 2\cdot 10^{18}\)。 题解:考虑约数个数公式,可以发现对于任意的\(a_i\),有\(a_i=\left\{\begi...

296

COSMO-RS理论:流体相热力学预测的核心模型与技术突破

摘要:COSMO-RS模型通过量子化学计算分子表面电荷分布,实现了从微观量子尺度到宏观化工过程的热力学预测。该模型基于介电连续介质理论,将分子表面片段化处理,通过σ-剖面描述电荷分布,并计算片段间的静电失配能和氢键能。其核心算法通过自洽化学势方程求解活度系数,克服了传统模型依赖实验参数的局限。随着技术进步,模型引入了高阶描述符和色散力修正,提升了预测精度。在药物研发、化工分离等领域广泛应用,但仍存在对长程有序结构预测不足等局限性。该模型为复杂体系的热力学性质预测提供了重要理论工具。

ASKCOS博客 981

Lyft Level 5 Challenge 2018 - Elimination Round题解【待补】

Lyft Level 5 Challenge 2018 - Elimination Round题解 A 以queen为原点,起点和终点必须分布在同一象限内 B \(a-b=1\), \(a+b\)为质数 C 按数字从小到大DP。 值为\(x\)的数字有\(n/x\)个后继,复杂度\(O(nlogn)\) D 最终只需求出每个质因子的指数即可,我们可以使用一个map,记录每个质因子对应的指数。 ...

weixin_30786617的博客 132

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Lyft Level 5 Challenge 2018 - Elimination Round翻车记

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

weixin_30794851的博客 149

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【补题】Codeforces 1033 : Lyft Level 5 Challenge 2018 - Elimination Round (ABCDF)

前言 又是发布失败,全部清空,重写一遍。 再这样一次,我就不用csdn了。 When everything’s lost they pick up their hearts and avenge defeat. League of Legends - Legends Never Die 总结 java.math.BigInteger.isProbablePrime(int)可以判断给定的概率...

秋叶红于二月花 821

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

华为OD机试200分题精讲:连接器问题与二分查找算法实战

在算法设计与优化中,二分查找是一种基于有序数据集合进行高效搜索的经典算法。其核心原理是通过不断将搜索区间对半分割,将时间复杂度从线性降至对数级,从而快速定位目标值。该技术的核心价值在于解决一大类“最小化最大值”或“最大化最小值”的优化问题,这类问题在资源分配、调度安排和参数寻优等工程场景中极为常见。例如,在连接器覆盖、木材切割或负载均衡等实际应用中,我们常需在满足约束条件下,寻找某个参数(如长度、容量)的最小或最大值。本文以华为OD机试高频考题“连接器问题”为具体案例,深入剖析如何将实际问题抽象为间隙数组的

dianxi0949的博客 396

Codeforces B. Square Difference

B. Square Difference time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alice has a lovely piece of cloth. It has the shape of a square with a si...

weixin_43888067的博客 370

Alice and Bob

Problem Description The famous "Alice and Bob" are playing a game again. So now comes the new problem which need a person smart as you to decide the winner. The problem is as follows: They are play

笑看风云起的专栏 1470

HDU 5724 Chess

Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other c

Occult 1288

cf----2019-10-05(Square Difference,Classy Numbers,Enlarge GCD)

城市黎明的灯火,总有光环在陨落,模仿者一个又一个,无人问津的角色,你选择去崇拜谁呢,怨恨谁呢? Alice has a lovely piece of cloth. It has the shape of asquarewith a side of lengthaacentimeters. Bob also wants such piece of cloth. He would pre...

0k-ok 384

Square Difference CodeForces - 1033B

Alice has a lovely piece of cloth. It has the shape of a square with a side of length a centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length b centimeters (w...

weixin_44488944的博客 342

状压+sg函数______Chess(hdu 5724 2016多校第一场)

Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other c

YzlCoder的记事本 1163

Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) C 数论

题目链接:http://codeforces.com/contest/1055/problem/C   题目思路:找到最大公因数,然后la,ra对ta取余,lb,rb对tb取余,然后求得la,lb之差,然后枚举k倍的最大公因数+la,算最大,这样时间复杂度太高,就直接将差/最大公因数=temp,枚举temp-1,temp,temp+1,求出最大值   AC代码 #include&lt;...

qq_36921652的博客 239
上一篇: POJ2492 A Bug's Life
下一篇: list::splice函数的使用
PX-C
博客等级 码龄9年 162粉丝 405原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值