AtCoder Beginner Contest 257 下分记录

A 题:

暴力拼串然后输出就行了。

string s;

signed main() 
{
	int n = read(), k = read();
	for(int i = 1; i <= 26; i++) {
		for(int j = 1; j <= n; j++) {
			s += i + 'A' - 1;
		}
	}
	cout << s[k - 1];
		return 0;
}

B题:

比着题目模拟就行了。

int n, k, Q;
int a[N];

signed main() 
{
	n = read(), k = read(), Q = read();
	for(int i = 1; i <= k; i++) a[i] = read();
	for(int i = 1; i <= Q; i++) {
		int x = read();
		if(a[x] == n) continue;
		if(a[x + 1] != a[x] + 1) a[x] = a[x] + 1;
	}
	for(int i = 1; i <= k; i++) cout << a[i] << " ";
	return 0;
}

C 题:

我们设 \(qzh[i][0/1]\) 表示从 \([1, i]\)\(0, 1\) 个数。

然后做法就很显然了, 排序后就可以用前缀和来搞了。

时间复杂度 \(\mathcal{O}(n)\)

int qzh[N][2], ans;

struct Node {
	int w, male;
	bool operator < (const Node &x) const {
		return w < x.w;
	}
}a[N];

signed main() 	
{
	int n = read();
	for(int i = 1; i <= n; i++) scanf("%1lld", &a[i].male);
	for(int i = 1; i <= n; i++) scanf("%lld", &a[i].w);
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++) {
		if(a[i].male == 1) qzh[i][1] = qzh[i - 1][1] + 1, qzh[i][0] = qzh[i - 1][0];
		else qzh[i][1] = qzh[i - 1][1], qzh[i][0] = qzh[i - 1][0] + 1;
	}
	for(int i = 0; i <= n; i++) {
		if(a[i].w == a[i + 1].w) continue;
		ans = max(ans, qzh[i][0] + qzh[n][1] - qzh[i][1]);
	}
	cout << ans;
	return 0;
} 
posted @ 2022-06-25 21:58  TLE_Automation  阅读(36)  评论(5)    收藏  举报