Codeforces Round #656 (Div. 3)

A. Three Pairwise Maximums

题意:

给你三个正整数 x y x、y z z ,请你找到正整数 a b a,b c c ,使得 x = m a x ( a b ) y = m a x ( a c ) , z = m a x ( b c ) x=max(a,b),y=max(a,c),z=max(b,c) ,或者确定不可能找到这样的 a b a,b c c

AC代码:

int main()
{
	int t;
	sd(t);
	while (t--)
	{
		int x, y, z;
		sddd(x, y, z);
		int maxn = max(x, max(y, z)), minn = min(x, min(y, z));
		if (x == y && x == maxn)
		{
			puts("YES");
			pddd(maxn, minn, minn);
		}
		else if (x == z && x == maxn)
		{
			puts("YES");
			pddd(minn, maxn, minn);
		}
		else if (y == z && y == maxn)
		{
			puts("YES");
			pddd(minn, minn, maxn);
		}
		else
			puts("NO");
	}
	return 0;
}

B. Restore the Permutation by Merger

题意:

有一种排列 p p ,将第二个 p p 的元素插入到第一个保持相对顺序的元素中,结果是长度为 2 n 2n 的序列 a a ,现给你插入后的序列 a a ,请你求出原序列 p p

记录每个元素出现的次数,顺序输出每次减去 2 2 ,判断剩下的是否满足大于等于 2 2 。.

AC代码:

const int N = 1e5 + 50;
int n, m;
int a[N];
int cnt[100];
int main()
{
	int t;
	sd(t);
	while (t--)
	{
		sd(n);
		mem(cnt, 0);
		rep(i, 1, 2 * n)
		{
			sd(a[i]);
			cnt[a[i]]++;
		}
		rep(i, 1, 2*n)
		{
			if (cnt[a[i]] >= 2)
			{
				printf("%d ", a[i]);
				cnt[a[i]] -= 2;
			}
		}
		printf("\n");
	}
	return 0;
}

C. Make It Good

题意:

如果能通过以下操作,从数组 b b 中获得一个非递减的数组 c c ,则成数组 b b 为好。选择 b b 的第一个或最后一个元素,将其从 b b 中删除,并将其附加到数组 c c 的末尾。

从后向前找一个连续的非减然后非增序列长度即可。

AC代码:

const int N = 1e5 + 50;
int n, m;
int a[N];
int cnt[100];
int main()
{
	int t;
	sd(t);
	while (t--)
	{
		sd(n);
		rep(i, 1, n)
			sd(a[i]);
		int cnt1 = 1, pos = -1, cnt2 = 0;
		per(i, 1, n - 1)
		{
			if (a[i] >= a[i + 1])
				cnt1++;
			else
			{
				pos = i;
				break;
			}
		}
		if (pos != -1)
		{
			cnt2 = 1;
			per(i, 1, pos - 1)
			{
				if (a[i] <= a[i + 1])
					cnt2++;
				else
					break;
			}
		}
		pd(n - cnt2 - cnt1);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43627087/article/details/107425354