【CodeForces】Lyft Level 5 Challenge 2018 - Elimination Round (Div. 1 + Div. 2) 题解

【比赛链接】

【题解链接】

**【A】**King Escape

【思路要点】

  • 皇后会攻击到 8 8 8 条直线,其中 4 4 4 条斜向的可以跨过,因此可以忽略。
  • 判断起始点和目标点是否在其余 4 4 4 条线分割出的同一个联通块内即可。
  • 时间复杂度 O ( 1 ) O(1) O(1)

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {
    
    x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {
    
    x = min(x, y); } 
template <typename T> void read(T &x) {
    
    
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
    
    
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
    
    
	write(x);
	puts("");
}
int n, ax, ay, bx, by, cx, cy;
int f(int x, int y) {
    
    
	int ans = 0;
	ans += x < ax;
	ans *= 2;
	ans += y < ay;
	return ans;
}
int main() {
    
    
	read(n);
	read(ax), read(ay);
	read(bx), read(by);
	read(cx), read(cy);
	if (f(bx, by) == f(cx ,cy)) printf("YES\n");
	else printf("NO\n");
	return 0;
}

**【B】**Square Difference

【思路要点】

  • 由题,我们要判断 a 2 − b 2 a^2-b^2 a2b2 是否是质数。
  • 由于 a 2 − b 2 = ( a + b ) ( a − b ) a^2-b^2=(a+b)(a-b) a2b2=(a+b)(ab) ,若 a − b &gt; 1 a-b&gt;1 ab>1 a 2 − b 2 a^2-b^2 a2b2 显然不是质数。
  • 否则则判断 a + b a+b a+b 是否为质数即可。
  • 时间复杂度 O ( a + b ) O(\sqrt{a+b}) O(a+b )

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {
    
    x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {
    
    x = min(x, y); } 
template <typename T> void read(T &x) {
    
    
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
    
    
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
    
    
	write(x);
	puts("");
}
bool prime(ll x) {
    
    
	for (int i = 2; 1ll * i * i <= x; i++)
		if (x % i == 0) return false;
	return true;
}
int main() {
    
    
	int T; read(T);
	while (T--) {
    
    
		ll a, b; read(a), read(b);
		if (a == b + 1 && prime(a + b)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

**【C】**Permutation Game

【思路要点】

  • 按照权值从大到小暴力博弈 d p dp dp 即可。
  • 时间复杂度 O ( N L o g N ) O(NLogN) O(NLogN)

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {
    
    x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {
    
    x = min(x, y); } 
template <typename T> void read(T &x) {
    
    
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
    
    
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
    
    
	write(x);
	puts("");
}
int n, a[MAXN], p[MAXN];
bool dp[MAXN];
bool cmp(int x, int y) {
    
    
	return a[x] > a[y];
}
int main() {
    
    
	read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]), p[i] = i;
	sort(p + 1, p + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
    
    
		int pos = p[i];
		for (int j = pos + a[pos]; j <= n; j += a[pos])
			if (a[j] > a[pos]) dp[pos] |= !dp[j];
		for (int j = pos - a[pos]; j >= 1; j -= a[pos])
			if (a[j] > a[pos]) dp[pos] |= !dp[j];
	}
	for (int i = 1; i <= n; i++)
		if (dp[i]) putchar('A'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值