Codeforces Round #731 (Div. 3)

Damn English questions!!It gives me a headache.

A Shortest Path with Obstacle

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;

typedef long long ll;
typedef pair<int, int> PII;
#define debug(a) cout << #a << " = " << a << endl
#define x first
#define y second

int main(void)
{
	int T, x[5], y[5];
	cin >> T;
	while (T--) {
		for (int i = 0; i < 3; i++) {
			scanf("%d%d", &x[i], &y[i]);
		}
		int res = abs(x[0] - x[1]) + abs(y[0] - y[1]);
		int maxv, minv;
		maxv = max(y[0], y[1]), minv = min(y[0], y[1]);
		if (x[0] == x[1] && x[1] == x[2] && y[2] <= maxv && y[2] >= minv)
			res += 2;
		maxv = max(x[0], x[1]), minv = min(x[0], x[1]);
		if (y[0] == y[1] && y[1] == y[2] && x[2] <= maxv && x[2] >= minv)
			res += 2;
		printf("%d\n", res);
	}
	
	return 0;
}

B Alphabetical Strings

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;

typedef long long ll;
typedef pair<int, int> PII;
#define debug(a) cout << #a << " = " << a << endl
#define x first
#define y second

int main(void)
{
	int T;
	char s[50];
	cin >> T;
	while (T--) {
		scanf("%s", s);

		int l = 0, r = strlen(s) - 1;
		int idx = r;
		while (idx > -1) {
			if (s[l] == 'a' + idx) {
				l++;
				idx--;
			} else if (s[r] == 'a' + idx) {
				r--;
				idx--;
			} else {
				break;
			}
		}
		if (idx == -1) puts("YES");
		else puts("NO");
	}
	
	return 0;
}

C Pair Programming

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;

typedef long long ll;
typedef pair<int, int> PII;
#define debug(a) cout << #a << " = " << a << endl
#define x first
#define y second

int a[305], b[305];
int res[605];

int main(void)
{
	int T;
	int k, n, m;
	cin >> T;
	while (T--) {
		scanf("%d%d%d", &k, &n, &m);
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
			//debug(a[i]);
		}
		for (int i = 0; i < m; i++) {
			scanf("%d", &b[i]);
		}
		int cnt = 0, i = 0, j = 0;
		int old = 0;
		while (cnt < n + m) {
			while (i < n) {
				if (a[i] == 0) {
					k++;
					res[cnt++] = a[i++];
				} else if (a[i] <= k) {
					res[cnt++] = a[i++];
				} else {
					break;
				}
			}
			while (j < m) {
				if (b[j] == 0) {
					k++;
					res[cnt++] = b[j++];
				} else if (b[j] <= k) {
					res[cnt++] = b[j++];
				} else {
					break;
				}
			}
			if (cnt == old)
				break;
			else
				old = cnt;
		}
		if (cnt < n + m) puts("-1");
		else {
			for (int i = 0; i < cnt; i++)
				printf("%d ", res[i]);
			puts("");
		}
	}
	
	return 0;
}

D Co-growing Sequence

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;

typedef long long ll;
typedef pair<int, int> PII;
#define debug(a) cout << #a << " = " << a << endl
#define x first
#define y second

int x[N];

int main(void)
{
	int T, n;
	cin >> T;
	while (T--) {
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			scanf("%d", &x[i]);
		}
		printf("0 ");
		int last = 0, t;
		for (int i = 1; i < n; i++) {
			t = (x[i - 1] | x[i]) ^ x[i];
			x[i] ^= t;
			printf("%d ", t);
		}
		puts("");
	}
	
	return 0;
}

E Air Conditioners

L[i] means the temperature that use left or ith air conditioner. R[i] is the same

So the answer is min(L[i], R[i])

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, INF = 0x3f3f3f3f;

typedef long long ll;
typedef pair<int, int> PII;
#define debug(a) cout << #a << " = " << a << endl
#define x first
#define y second
// c 表示空调 
int a[N], t[N], c[N];
// 用左边空调的温度,用右边空调的温度 
int L[N], R[N];

int main(void)
{
	int q, n, k;
	cin >> q;
	while (q--) {
		scanf("%d%d", &n, &k);
		for (int i = 0; i < k; i++) {
			scanf("%d", &a[i]);
		}
		for (int i = 0; i < k; i++) {
			scanf("%d", &t[i]);
		}
		// 记录每个地点的温度 
		memset(c, 0x3f, sizeof c);
		for (int i = 0; i < k; i++) {
			c[a[i] - 1] = t[i];
		}
		
		int p = INF;
		memset(L, 0x3f, sizeof L);
		for (int i = 0; i < n; i++) {
			p = min(p + 1, c[i]);
			L[i] = p;
		}
		p = INF;
		memset(R, 0x3f, sizeof R);
		for (int i = n - 1; i >= 0; i--) {
			p = min(p + 1, c[i]);
			R[i] = p;
		}
		
		for (int i = 0; i < n; i++) {
			printf("%d ", min(L[i], R[i]));
		}
	}
	
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值