欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 美景 > Codeforces Round 952 (Div. 4)

Codeforces Round 952 (Div. 4)

2024/10/23 23:25:24 来源:https://blog.csdn.net/weixin_73793099/article/details/140110728  浏览:    关键词:Codeforces Round 952 (Div. 4)

目录

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;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com