Codeforces Round 952 (Div. 4)

发布于:2024-07-01 ⋅ 阅读:(14) ⋅ 点赞:(0)

目录

A. Creating Words

B. Maximum Multiple Sum

D. Manhattan Circle


A. Creating Words

题意:交换两个数组的第一个字符

AC代码:

#include <bits/stdc++.h>
#define int long long
#define PII std::pair<int,int>
signed main() {
    int t;
    std::cin >> t;
    while (t--) {
        std::string s1, s2;
        std::cin >> s1 >> s2;
        char ch = s1[0];
        s1[0] = s2[0];
        s2[0] = ch;
        std::cout << s1 << " " << s2 << "\n";
    }
    return 0;
}

B. Maximum Multiple Sum

题意:给一个数n,2<=x<=n,x+2x+3x+...+kx,其中kx<=n;求总和最大的数对应的x

这道题数据范围很小,暴力就行

AC代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#define int long long
#define PII std::pair<int,int>
signed main()
{
	int t;
	std::cin >> t;
	while (t--)
	{
		int n;
		std::cin >> n;
		int maxx = -999;
		int maxi ;
		for (int i = 2;i <= n;i++)
		{
			int num = 0;
			int x = i;
			while (x <= n)
			{
				num += x;
				x += i;
			}
			//std::cout << x << "\n";
			if (num > maxx)
			{
				maxx = num;
				maxi = i;
			}

		}
		std::cout << maxi << "\n";
	}
	return 0;
}

D. Manhattan Circle

题意:求#围城的图的中心

思路:分别求出边界点的,y

AC代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#define int long long
#define PII std::pair<int,int>
const int N = 2e5 + 10;
//char g[N][N];
signed main()
{
	int t;
	std::cin >> t;
	while (t--)
	{
		int n, m;
		std::cin >> n >> m;
		//std::vector<std::vector<int>> g;
		std::vector<std::vector<char> >g(n + 10, std::vector<char>(m + 10,0));
	    //char g[n+10][m+10];
		int zuox = 99999999, youx =0, shangy = 99999999, xiay = 0;
		for (int i = 1;i <= n;i++)
		{
			for (int j = 1;j <= m;j++)
			{
				std::cin >> g[i][j];
				if (g[i][j] == '#')
				{
					zuox = std::min(zuox, i);
					youx = std::max(youx, i);
					shangy = std::min(shangy, j);
					xiay = std::max(xiay, j);
				}
			}
		}
		//int zuox=99999999, youx=0, shangy=99999999, xiay=0;
	/*	for (int i = 1;i <= n;i++)
		{
			for (int j = 1;j <= m;j++)
			{
				if (g[i][j] == '#')
				{
					zuox = std::min(zuox, i);
					youx = std::max(youx, i);
					shangy = std::min(shangy, j);
					xiay = std::max(xiay, j);
				}
			}
		}
		*/
		std::cout << (zuox + youx) / 2 << " " << (shangy + xiay) / 2 << "\n";
	}
	return 0;
}