Educational Codeforces Round 107 (Rated for Div. 2)(A~D)

比赛链接:这里
A:
题解:这个有两个服务器,贪心的想,我们把差评放在第二个服务器,其余的放在第一个服务器,这样中立就可以变为好评了,这样可以得到最大。

#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
#define ios ios::sync_with_stdio(false)
#define CRL(a) memset(a,0,sizeof a)

using namespace std;

const int maxn = 3e5 + 5;

int x[maxn];
int y[55];
int main()
{
    ios;
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n;i++)
    {
        int a;
        cin>>a;
        if(!y[a])
            y[a] = i;
    }
    for (int i = 1; i <= q;i++)
    {
        int a;
        cin >> a;
        cout << y[a] << " ";
        int b = y[a];
        y[a] = 1;
        for (int j = 1; j <= 50;j++)
        {
            if(j==a)
                continue;
            if(y[j]<b)
                y[j]++;
        }
    }
}

B:
题解:让你构造两个数,一个长度为a,一个长度为b,他们的最大公约数长度为c。
构造题,用素数即可构造,具体看代码。

#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
#define ios ios::sync_with_stdio(false)
#define CRL(a) memset(a,0,sizeof a)

using namespace std;

const int maxn = 3e5 + 5;
char x[405][405];
int main()
{
    ios;
    int t;
    cin >> t;
    while(t--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        if(a==b&&b==c&&c==1)
        {
            cout << 1 << " " << 1 << endl;
            continue;
        }
        int d = 1;
        for (int i = 1; i < c;i++)
        {
            d = d * 10 + 1;
        }
        int e = a - c;
        int f = pow(10, e);
        e = b - c;
        int g = pow(10, e);
        cout << d * f << " " << d * g + d << endl;
    }
}

C:
题解:注意这个题数据范围只有50,相同的数只有第一个有效,我们只需要存下第一个的位置,然后暴力解决就ok。

#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
#define ios ios::sync_with_stdio(false)
#define CRL(a) memset(a,0,sizeof a)

using namespace std;

const int maxn = 3e5 + 5;

int x[maxn];
int y[55];
int main()
{
    ios;
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n;i++)
    {
        int a;
        cin>>a;
        if(!y[a])
            y[a] = i;
    }
    for (int i = 1; i <= q;i++)
    {
        int a;
        cin >> a;
        cout << y[a] << " ";
        int b = y[a];
        y[a] = 1;
        for (int j = 1; j <= 50;j++)
        {
            if(j==a)
                continue;
            if(y[j]<b)
                y[j]++;
        }
    }
}

D:
题解:构造题,其实这个题看第一个样例就可以知道怎么构造是最优的,a后面先放a,再放b,b后面再放a,a后面再放c,就这么循环下去求出k个字母的最长串,如果n的长度大于这个串的长度,那我们在后面循环这个即可。

#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
#define ios ios::sync_with_stdio(false)
#define CRL(a) memset(a,0,sizeof a)

using namespace std;

const int maxn = 2e5 + 5;

int x[30] = {0};
int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	for (int i = 1; i < k;i++)
	{
		s += 'a' + i - 1;
		while(1)
		{
			int a = s[s.size()-1] - 'a';
			s += 'a' + x[a];
			x[a]++;
			if(x[a]==k)
				break;
		}
	}
	s += 'a' + k - 1;
	string s1;
	if(n<=s.size())
	{
		for (int i = 0; i < n;i++)
		{
			s1 += s[i];
		}
	}
	else 
	{
		int a = n / s.size();
		int b = n % s.size();
		for (int i = 0; i < a;i++)
		{
			s1 += s;
		}
		for (int i = 0; i < b;i++)
		{
			s1 += s[i];
		}
	}
	cout << s1;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值