Codeforces Round #614 (Div. 2) 解题报告

Codeforces Round #614 (Div. 2)

【A. ConneR and the A.R.C. Markland-N】

【题目大意】
有n层楼,每层楼都有餐厅,每层之间有楼梯,你在s楼,现在有k层楼的餐厅关门了,问你至少要走几层楼梯才能吃饭

【解题思路】
首先,如果s楼的餐厅没有关门,那么答案显然为0
否则对k层楼进行排序,找到包含s楼的连续区间,对区间末尾取最小值就可以了

注意,当区间末尾为0或n+1时说明区间下限或上限不可取

【AC代码】

#include <bits/stdc++.h>
#define max(a, b) ((a) > (b) ? (a) :(b))
#define min(a, b) ((a) < (b) ? (a) :(b))
#define _Rep(i, n) for(register int i = 1; i < (n); ++i)
#define Rep(i, n) for(register int i = 1; i <= (n); ++i)
#define _rep(i, n) for(register int i = 0; i < (n); ++i)
#define rep(i, n) for(register int i = 0; i <= (n); ++i)
using namespace std;
const int maxn = 1e6 + 10;
const int maxm = 3e5 + 10;
int a[1010];
inline int read() {
	register int x = 0, w = 0; register char ch = 0;
	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return w ? -x : x;
}
inline void write(register int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
int main() {
	register int t = read();
	while (t--) {
		register int n = read(), s = read(), k = read();
		register int ans = 0;
		Rep(i, k) {
			a[i] = read();
			if (a[i] == s) ans = INF;
		}
		if (!ans) {
			puts("0");
			continue;
		}
		sort(a + 1, a + k + 1);
		register int i = 1;
		for (i = 1; i <= k; ++i) {
			if (a[i] >= s) break;
		}
		int l = i, r = i;
		for (i = l; i > 0; --i) {
			if (a[i] != a[i - 1] + 1) break;
		}
		if (a[i] > 1) ans = s - a[i] + 1;
		for (i = r; i < k; ++i) {
			if (a[i + 1] != a[i] + 1) break;
		}
		if (a[i] < n) ans = min(ans, a[i] - s + 1);
		printf("%d\n", ans);
	}
	return 0;
}

【B. JOE is on TV!】

【题目大意】
有n个人和你进行问答游戏,每轮游戏你获得的奖金数为该轮淘汰人数除以该轮总人数,问你最后获得的最大奖金数为多少

【解题思路】
可以证明每轮淘汰一个人的时候奖金数最大

【AC代码】

#include <bits/stdc++.h>
#define N 100
#define max(a, b) ((a) > (b) ? (a) :(b))
#define min(a, b) ((a) < (b) ? (a) :(b))
#define _Rep(i, n) for(register int i = 1; i < (n); ++i)
#define Rep(i, n) for(register int i = 1; i <= (n); ++i)
#define _rep(i, n) for(register int i = 0; i < (n); ++i)
#define rep(i, n) for(register int i = 0; i <= (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const int maxm = 3e5 + 10;
const ll INF = 0x3f3f3f3f;
inline int read() {
	register int x = 0, w = 0; register char ch = 0;
	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return w ? -x : x;
}
inline void write(register int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
int main() {
	register int n = read();
	double ans = 0.0;
	for (int i = 1; i <= n; ++i) {
		ans += double(1 / (double(i * 1.0)));
	}
	printf("%.12f\n", ans);
	return 0;
}

【C. NEKO’s Maze Game】

【题目大意】
有一个2 * n的矩阵,1 - q的每个时间点都会有格子变成陷阱,或者从陷阱变回地面,问你1 - q的每个时间点是否可以从(1, 1)到达(2, n)

【解题思路】
惭愧啊惭愧,这题最后也没写出来,其实正解很简单,因为矩阵是2 * n的,那么记录所有竖着相连的陷阱个数就可以了,当其个数为0是不可到达,否则可以到达

【AC代码】

#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
inline int read() {
	register int x = 0, w = 0; register char ch = 0;
	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return w ? -x : x;
}
inline void write(register int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
bool vis[3][maxn];
int main() {
	register int n = read(), q = read();
	register int cnt = 0;
	while (q--) {
		register int x = read(), y = read();
		if (vis[x][y]) {
			if (vis[3 - x][y]) --cnt;
			if (vis[3 - x][y - 1]) --cnt;
			if (vis[3 - x][y + 1]) --cnt;
			vis[x][y] = false;
		}
		else {
			if (vis[3 - x][y]) ++cnt;
			if (vis[3 - x][y - 1]) ++cnt;
			if (vis[3 - x][y + 1]) ++cnt;
			vis[x][y] = true;
		}
		cnt ? puts("No") : puts("Yes");
	}
	return 0;
}

【D. Aroma’s Search】

【题目大意】
有一个无限的网格,有一些网格有数据,这些网格坐标满足

第一个坐标为 (x0, y0)
第i个坐标为(ax⋅x[i−1] + bx, ay⋅ y[i−1] + by)

你从(xs, xy)出发,每向相邻的格子移动一下会花费1s时间,总时间为t,问你能拿到的最多数据是多少,每个数据仅能拿走一次

【解题思路】
根据画图容易得到,当你从第i个数据点到达第j个数据点,你可以经过i和j中间的所有数据点
首先找到t时间内能到达的所有网格,然后O(n2)遍历这些网格,利用最短路径的思想,考虑从起始点到达第i个坐标后看能否在t时间内到达第j个数据点,那么ans = max(ans, abs(j - i) + 1)

【AC代码】

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
struct Node {
	ll x, y;
	Node() :x(0), y(0) {}
	Node(ll mx, ll my) :x(mx), y(my) {}
}p[maxn];
inline ll read() {
	register ll x = 0, w = 0; register char ch = 0;
	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return w ? -x : x;
}
inline void write(register ll x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
inline ll max(ll x, ll y) { return x > y ? x : y; }
inline ll cal_time(Node& a, Node& b) {
	return abs(a.x - b.x) + abs(a.y - b.y);
}
int main() {
	register ll x0 = read(), y0 = read(), ax = read(), ay = read(), bx = read(), by = read(), xs = read(), ys = read(), t = read();
	register int cnt = 1;
	p[0] = Node(xs, ys);
	p[1] = Node(x0, y0);
	while (true) {
		++cnt;
		p[cnt] = Node(ax * p[cnt - 1].x + bx, ay * p[cnt - 1].y + by);
		if (p[cnt].x + p[cnt].y - p[0].x - p[0].y > t) break;  //注意这里不能用cal_time函数,因为要找的最远点是处于(xs, ys)右上方的格子
	}
	register int ans = 0;
	for (register int i = 1; i < cnt; ++i) {
		for (register int j = 1; j < cnt; ++j) {
			if (cal_time(p[0], p[i]) + cal_time(p[i], p[j]) > t) continue;
			ans = max(ans, abs(j - i) + 1);
		}
	}
	printf("%d\n", ans);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值