比赛地址
A. Acwing 4716. 进球
题意:
n 行输入两个不同的字符串,表示球队进球,求哪支球队获胜
思路:
用 unordered_map<string, int> map, 进行存储,因为一共两支球队,n 次进球,当一支球队的进球数大于 n / 2 说明该球队获胜
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define int long long
#define div() cout << "-----------------------------" << endl
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 55;
int n;
int a[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
unordered_map<string, int> map;
for (int i = 0; i < n; i ++)
{
string s;
cin >> s;
map[s] ++;
if (map[s] > n / 2)
{
cout << s << endl;
break;
}
}
return 0;
}
B. AcWing 4717. 环形队伍
题意:
用七种颜色给由 n 个人组成的环形队伍染色,要求每相邻四个人颜色各不相同
思路:
假设七种颜色为0 ~ 6,先给前7个分别涂上0 ~ 6,后面对 3 ~ 6 循环涂色
eg:
0123456 3456 3456 3456 …
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define int long long
#define div() cout << "-----------------------------" << endl
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 100 + 5;
int n;
int a[N];
bool st[N];
bool cnt[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
string s = "ROYGBIV";
string res;
res += s;
n -= 7;
for (int i = 0; i < n; i ++)
res += s[i % 4 + 3];
cout << res << endl;
return 0;
}
C. AcWing 4718. 弹球线路
题意:
思路:
并查集,难
AC代码: