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;
}