比赛链接:这里
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;
}