补题--13 Codeforces Round #659 (Div. 2)

Codeforces Round #659 Div. 2


比赛网址: https://codeforces.com/contest/1384

A

题意:
就是输入n个数组a[n],然后是s[i]和·s[i+1]的前缀相同的个数是a[i],然后输出n+1个这个s[i]的字符串.
思路:
就是除了第一个和最后一个输出的时候只看第一个a【第一个】和a【最后一个】,其他的中间的则要进行比较a[i]与a[i+1]的大小,那个大则前缀相同的程度就是那个。
代码:

#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
typedef long long ll;
using namespace std;
ll n,m,k,ans,aans,flag,num,cnt,l,r,a[200];
char c,s[200];
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
   while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        cin>>a[i];
        c='a';
        for(int i=1;i<=n+1;i++)
        {
            l=r=0;
            if(i==1)
            {
                for(int j=1;j<=a[i];j++)
                {
                    cout<<c;
                    s[j]=c;
                }
                aans=a[i];
                cout<<(i%2?"y":"z");
                cout<<endl;
            }
            else if(i==n+1)
            {
 
                for(int j=1;j<=a[n];j++)
                cout<<s[j];
                cout<<(i%2?"y":"z");
                cout<<endl;
            }
            else
            {
                aans=max(a[i],a[i-1]);
                if(aans>a[i-1])
                {
                    if(c=='x') c='a';
                    else c++;
                }
                for(int j=1;j<=aans;j++)
                {
                    if(j<=a[i-1])
                    cout<<s[j];
                    else
                    {
                        cout<<c;
                        s[j]=c;
                    }
                }
                cout<<(i%2?"y":"z");
                cout<<endl;
            }
        }
    }
    return 0;
}

B

https://codeforces.com/contest/1384/problem/B1
这一题我看了官方代码也没有太懂今天然后就上网搜了搜然后就找到这个一个小姐姐的代码
官方:

#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int test;
	cin >> test;
	while (test--)
	{
		int n, k, l;
		cin >> n >> k >> l;
		vector<int> d(n+2, -k);
		for (int i = 1; i <= n; ++i)
			cin >> d[i];

		set<tuple<int, int, bool>> mark;
		function<bool(int, int, bool)> go = [&](int pos, int tide, bool down)
		{
			if (pos > n) return true;
			
			if (mark.find({ pos, tide, down }) != mark.end())
				return false;

			mark.insert({ pos, tide, down });

			tide += down ? -1 : +1;
			if (tide == 0) down = false;
			if (tide == k) down = true;

			if (d[pos] + tide <= l && go(pos, tide, down))
				return true;
			if (d[pos + 1] + tide <= l && go(pos + 1, tide, down))
				return true;
			return false;
		};

		if (go(0, 0, false)) cout << "Yes\n";
		else cout << "No\n";
	}

	return 0;
}

C

题意:
就是给定两个字符串 a ,b 然后可以把 a中所有相同的字符换成比它大的一个任何字符 ,输出把a变成b在最少次数。
我的思路是有一点但是还是很缺陷,然后看了官方代码。
官方代码:

#include <bits/stdc++.h>

using namespace std;

const int Alp = 20;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int test;
	cin >> test;
	while (test--)
	{
	    int n;
		string a, b;
		cin >> n >> a >> b;

		bool bad = false;
		vector<vector<int>> adj(Alp);
		for (int i = 0; i < n; ++i)
			if (a[i] != b[i])
			{
				if (a[i] > b[i])
				{
					bad = true;
					cout << "-1\n";
					break;
				}

				adj[a[i]-'a'].push_back(b[i]-'a');
				adj[b[i]-'a'].push_back(a[i]-'a');
			}

		if (bad) continue;

		vector<bool> mark(Alp);
		function<void(int)> dfs = [&](int u)
		{
			mark[u] = true;
			for (auto v : adj[u])
				if (!mark[v])
					dfs(v);
		};

		int ans = Alp;
		for (int i = 0; i < Alp; ++i)
			if (!mark[i])
				dfs(i), --ans;
		cout << ans << "\n";
	}

	return 0;
}

总结

这次比赛就搞定了一道题目,然后我的分数本来跌倒了谷底,但是因为这一次做了一题还加了101,还是可以的,进行加油!
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值