Acwing 第77场周赛

比赛地址

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代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值