A题: Stair, Peak, or Neither?
签到题
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
inline void solve() {
int a, b, c; cin >> a >> b >> c;
if (a < b and b < c) cout << "STAIR\n";
else if (a < b and b > c) cout << "PEAK\n";
else cout << "NONE\n";
return;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int _; cin >> _;
while (_ -- ) solve();
return 0;
}
B题: Upscaling
找出规律,我是一行一行操作的。
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
inline void solve() {
int n; cin >> n;
string s1, s2;
for (int i = 1; i <= n; i ++ ) {
if (i & 1) {
s1 += "##";
s2 += "..";
}else {
s1 += "..";
s2 += "##";
}
}
for (int i = 1; i <= n; i ++ ) {
if (i & 1) {
cout << s1 << endl;
cout << s1 << endl;
}else {
cout << s2 << endl;
cout << s2 << endl;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int _; cin >> _;
while (_ -- ) solve();
return 0;
}
C题: Clock Conversion
知识点:时间转化
24小时: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
12小时:12 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11
从上面可以看出,当24小时下,小于12的是AM
12小时 = (24小时 + 11) % 12 + 1
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
inline void solve() {
string s; cin >> s;
int h = (s[0] - '0') * 10 + s[1] - '0';
int h1 = (h + 11) % 12 + 1;
s[0] = h1 / 10 + '0', s[1] = h1 % 10 + '0';
cout << s << ' ' << (h < 12 ? "AM" : "PM") << endl;
return;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int _; cin >> _;
while (_ -- ) solve();
return 0;
}
D题: Product of Binary Decimals
数据小,可以直接把符合01的十进制数全部拿出来,然后暴力下
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
vector<int> v;
set<int> ans;
bool check(int x) {
while (x) {
if (x % 10 > 1) return false;
x /= 10;
}
return true;
}
inline void pre_work() {
for (int i = 1; i <= 1e5; i ++ )
if (check(i)) v.push_back(i);
for (int a1 : v) {
for (int a2 : v) {
if (a2 == 1) continue;
int sum = a1 * a2;
while (sum <= 1e5) {
ans.insert(sum);
sum *= a2;
}
}
}
ans.insert(1);
}
inline void solve() {
int x; cin >> x;
if (ans.count(x)) cout << "YES\n";
else cout << "NO\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
pre_work();
int _; cin >> _;
while (_ -- ) solve();
return 0;
}
E题: Nearly Shortest Repeating Substring
找最小周期字串,但是可以一个字符不同,暴力枚举长度计算即可
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
inline void solve() {
int n; string s;
cin >> n >> s;
s = " " + s;
for (int i = 1; i <= n; i ++ ) {
if (n % i != 0) continue;
int sum = 0;
for (int j = 1; j <= i; j ++ ) {
vector<int> cnt(26);
int mx = 0;
for (int k = j; k <= n; k += i) {
cnt[s[k] - 'a'] ++;
mx = max(mx, cnt[s[k] - 'a']);
}
sum += mx;
}
if (sum >= n - 1) return cout << i << endl, void();
}
return;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}
F题: 0, 1, 2, Tree!
输出-1的情况是c != a + 1
因为b的多少对c的需求没有任何关系
因为求高度,我们可以打一遍bfs
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
inline void solve() {
int a, b, c; cin >> a >> b >> c;
if (c != a + 1) cout << -1 << endl;
else {
int ans = 0;
queue<int> q;
q.push(0);
while (q.size()) {
int x = q.front(); q.pop();
if (a) {
q.push(x + 1);
q.push(x + 1);
a --;
}else if (b) {
q.push(x + 1);
b --;
}
ans = x;
}
cout << ans << endl;
}
return;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}
G题: Shuffling Songs
const int N = 20, M = 1 << 16;
int n;
string a[N], b[N];
bool dp[M][N];
vector<int> e[N];
inline int cal(int x) {
int ans = 0;
while (x) ans += x % 2, x /= 2;
return ans;
}
inline void dfs(int st, int u) {
if (dp[st][u]) return;
dp[st][u] = true;
for (auto nx : e[u]) {
if (st & (1 << nx)) continue;
dfs(st | (1 << nx), nx);
}
}
inline void solve() {
cin >> n;
for (int i = 0; i < (1 << n); i ++ ) {
for (int j = 0; j < n; j ++ ) {
dp[i][j] = false;
}
}
for (int i = 0; i < n; i ++ ) e[i].clear();
for (int i = 0; i < n; i ++ ) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; i ++ ) {
for (int j = i + 1; j < n; j ++ ) {
if (a[i] == a[j] || b[i] == b[j]) {
e[i].push_back(j);
e[j].push_back(i);
}
}
}
for (int i = 0; i < n; i ++ ) {
dfs(1 << i, i);
}
int mx = 0;
for (int i = 0; i < (1 << n); i ++ ) {
for (int j = 0; j < n; j ++ ) {
if (dp[i][j]) mx = max(mx, cal(i));
}
}
cout << n - mx << endl;
return;
}