A. Omkar and Bad Story
题目大意
给定一个数组a要求在其中添加一些数变成数组b,要求对数组b中任意bi,bj都有 abs(bi-bj) 在b这个数组中出现,判断能否构造这样一个数组b,如果可以,可以按任意顺序输出数组b中的所有元素。
解题思路
首先若数组中存在负数必然不行,每次添加一个数都会扩展出新的不存在的数,所以就可以判定成立条件,那么对于满足的数组,最简单的方法就是直接将其补充为,包含从0到原数组最大值的数组。
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7;
const int N = 1e5 + 100;
int c[N], a[N], b[N];
ll dp[N];
vector<int> G[N];
int main(){
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
map<int, bool> p;
bool cann = 1;
int maxx = 0;
for (int i = 1; i <= n;i++){
cin >> a[i];
p[a[i]] = true;
if(a[i] < 0){
cann = 0;
}
maxx = max(maxx, a[i]);
}
if(!cann){
cout << "NO" << endl;
continue;
}
if(cann){
cout << "YES" << endl;
cout << maxx + 1 << endl;
for (int i = 0; i <= maxx;i++){
cout << i << ' ';
}
cout << endl;
}
}
return 0;
}
B. Prinzessin der Verurteilung
题目大意
(这次的题出的真是难懂…)
给你一个字符串,让你按长度最短原则,按字典序排序输出最小的,并且没有在给定字符串中出现的字符串。
解题思路
注意n的范围很小,推一下字母的排列组合就可以判断输出的答案最长为3,直接暴力即可。
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7;
const int N = 1e5 + 100;
int c[N], a[N], b[N];
char s[1010];
bool num[1000];
vector<int> G[N];
int main(){
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
memset(num, 0, sizeof num);
int n;
cin >> n;
map<string, bool> p;
for (int i = 1; i <= n;i++){
cin >> s[i];
}
int len = 0;
while(len<=2){
for (int i = 1; i <= n;i++){
int tot = i + len;
if(tot<=n){
string ss;
for (int j = i; j <= tot;j++){
ss.push_back(s[j]);
}
p[ss] = 1;
}
}
len++;
}
bool cann = 0;
for (char i = 'a'; i <= 'z';i++){
string s1;
s1.push_back(i);
if(!p[s1]){
cout << s1 << endl;
cann = 1;
break;
}
}
if(!cann){
for (char i = 'a'; i <= 'z';i++){
for (char j = 'a'; j <= 'z';j++){
string s2;
s2.push_back(i);
s2.push_back(j);
if(!p[s2]){
cout << s2 << endl;
cann = 1;
break;
}
}
if(cann)
break;
}
}
if(!cann){
for (char i = 'a'; i <= 'z';i++){
for (char j = 'a'; j <= 'z';j++){
for (int k = 'a'; k <= 'z';k++){
string s3;
s3.push_back(i);
s3.push_back(j);
s3.push_back(k);
if(!p[s3]){
cout << s3 << endl;
cann = 1;
break;
}
}
if(cann)
break;
}
if(cann)
break;
}
}
}
return 0;
}
C. Diluc and Kaeya
题目大意
给定一个只包含K,D的字符串,要求你尽可能把这个串分成多份,每一份的D的个数和K的个数的比值都相同,最后输出n个数,第 i 个数代表对于前 i 个字符构成的字符串最多能分成多少份
解题思路
每一次输入一个字符,就记录当前比值,若某个比值重复出现,那么代表这个比值的分子,分母都成倍增加了一次,那么一定可以分出一个额外的块,即重复的次数就是答案。用map记录即可
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7;
const int N = 1e5 + 100;
int c[N], a[N], b[N];
char s[1010];
bool num[1000];
vector<int> G[N];
int gcd(int a,int b)
{
return b ? gcd(b,a % b) : a;
}
int main(){
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
memset(num, 0, sizeof num);
int n;
cin >> n;
map<PII, int> p;
int d = 0, k = 0;
for (int i = 1; i <= n;i++){
cin >> s[i];
if(s[i]=='D'){
d++;
}
else{
k++;
}
p[make_pair(d / gcd(d, k), k / gcd(d, k))]++;
cout << p[make_pair(d / gcd(d, k), k / gcd(d, k))] << ' ';
}
cout << endl;
}
return 0;
}