人均三题。。。终究还是我low了。
A题
题目长,但意思很简单,直接贪心就好,只需要将每个点赞放到一个系统,每个踩放到另一个系统就好了,那么答案就是r1和r3的和。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 55;
int n;
int g[N];
int main()
{
int T;
cin >> T;
while (T -- )
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> g[i];
int res = 0;
for (int i = 1; i <= n; i ++ )
{
if (g[i] == 1) res ++ ;
else if (g[i] == 3) res ++ ;
}
cout <<res << endl;
}
return 0;
}
B题
打表即可。找到对应c位数的质数,并且不断乘2来得到a和不断乘3得到b,由于这样a的最小质因子为c和2,b的最小质因子为c和3,所以两个的最大公约数为c。
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
LL s[10] = {0, 7, 97, 997, 9973, 99991, 999983, 9999937, 99999989, 999999797};
int get(int x)
{
int res = 0;
while(x)
{
res ++ ;
x /= 10;
}
return res;
}
int main()
{
int T;
cin >> T;
while(T -- )
{
int a, b, c;
cin >> a >> b >> c;
int x = s[c],y = s[c];
while(get(x) < a) x *= 2;
while(get(y) < b) y *= 3;
cout << x << ' ' << y << endl;
}
return 0;
}
C题
由于数据范围比较小最多只有50种颜色,所以只需要记录一下每一种颜色的最小值即可,在找到一种颜色并放到最上面时,只需将小于这种颜色位置的颜色全部后移一位。
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 300010;
int n, m;
int g[N];
int tr[N];
int s[N];
int lowbit(int x)
{
return x & -x;
}
int ask(int x)
{
int res = 0;
for (int i = x; i ; i -= lowbit(i)) res += tr[i];
return res;
}
void add(int x, int k)
{
for (int i = x; i <= n; i += lowbit(i)) tr[i] += k;
}
int main()
{
cin >> n >> m;
memset(s, 0x3f, sizeof s);
for (int i = 1; i <= n; i ++ )
{
cin >> g[i];
s[g[i]] = min(s[g[i]], i);
}
while (m -- )
{
int t;
cin >> t;
cout << s[t] << ' ';
for (int i = 1; i <= 50; i ++ )
if (s[i] >= 1 && s[i] < s[t])
s[i] ++ ;
s[t] = 1;
}
return 0;
}
D题
由于字符只有26个,所以只需要将每个字符对的数量存下来,并且每次寻找冲突最小的字符对进行插入即可。(hash思想)
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 200010;
int n, m;
char s[N];
int g[N];
int main()
{
cin >> n >> m;
s[0] = 'a';
int last = 0;
for (int i = 1; i < n; i ++ )
{
int maxv = 0x3f3f3f3f, d = -1;
for (int j = 0; j < m; j ++ )
{
if (maxv >= g[last * 26 + j])
{
maxv = g[last * 26 + j];
d = j;
}
}
s[i] = d + 'a';
g[last * 26 + d] ++ ;
last = d;
}
for (int i = 0; i < n; i ++ ) cout << s[i];
return 0;
}