A. Cards(模拟)
题目链接:codeforces 1220A
题意:
给一个包含n个字符的字符串(只包含' z' ,'e' ,' r' , 'o' ,'n'),问重新组合之后包含最多的 'zero' 和 'one'字符串 的个数,一个字符只能使用一次
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int t;
cin >> t;
string s;
cin >> s;
int z = 0, e = 0, r = 0, o = 0, n = 0, ans0 = 0, ans1 = 0;
for(int i = 0; i < t; i++){
if(s[i] == 'z'){
z++;
}
else if(s[i] == 'e'){
e++;
}
else if(s[i] == 'r'){
r++;
}
else if(s[i] == 'o'){
o++;
}
else{
n++;
}
}
if(z >= n || r >= n){
ans0 = min(z, min(e, min(r, o)));
ans1 = min(n, min(o-ans0, e-ans0));
}
else{
ans1 = min(n, min(o, e));
ans0 = min(z, min(e-ans1, min(r, o-ans1)));
}
for(int i = 1; i <= ans1; i++){
cout << "1 ";
}
for(int i = 1; i <= ans0; i++){
cout << "0 ";
}
return 0;
}
B. Multiplication Table(思维)
题目链接:codeforces 1220B
题意:
给一个n * n 的矩阵M, M[i][j]= a[i] * a[j] (a为数组),求这个数组
题解:
要求这个数组,只要确定 a[1]即可,其他可以根据 M[1][j] / a[1] 求得, a[1] * a[1] = M[1][2] * M[1][3] / M[2][3]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3+10;
int a[maxn][maxn];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n;i++){
for(int j = 1; j <= n; j++){
cin >> a[i][j];
}
}
ll a1 = sqrt(1ll*a[1][2] * a[1][3] / a[2][3]);
cout << a1;
for(int i = 2; i <= n; i++){
cout <<" " << a[1][i] / a1;
}
cout << endl;
return 0;
}
C. Substring Game in the Lesson(思维)
题目链接:codeforces 1220C
题意:(有点难理解)
就是给定一个字符串,每次从第i个位置开始,向两边扩展,能否找到一个字符串的字典序小于当前字符串,不能就输,Ann先手,Mike后手
题解:
题目上说可以往两边扩展,但是往后扩展必然将导致字符串字典序变大,所以只能往前扩展,如果前一个字符小于当前字符,那么先手赢,否则后手赢
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 105;
int a[maxn];
int main(){
string s;
cin >> s;
int len = s.size();
cout << "Mike" << endl;
for(int i = 1; i < len; i++){
if(s[i-1] < s[i]){
s[i] = s[i-1];
cout << "Ann" << endl;
}
else{
cout << "Mike" << endl;
}
}
return 0;
}