Contestant. Rank 3721. Rating +41. A. Many A+B Problems 题意 给定 \(a, b\),输出 \(a + b\)。 思路 如题 时间复杂度:\(O(1)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(0); int t; cin >> t; while(t --){ int a, b; cin >> a >> b; cout << a + b << '\n'; } return 0; } 怎么会是呢 B. Qualification Contest 题意 给定 \(n\) 个由小写字母组成的字符串,输出字典序升序排序的前 \(k\) 个字符 ...
Contestant. Rank 2199. Rating +10. A. Two Towers 题意 给定由两种不同颜色的元素叠成的塔,定义操作为将一个塔上的顶部元素移动到另一个塔,在若干次操作后,输出是否可以让两个塔的元素颜色相间。 思路 显然,这个问题可以抽象为:给定一个元素序列,找出一个点,将序列分成两半,使分割后的序列颜色相间。 那么,我们需要满足两个条件: 序列内没有连续 \(3\) 个及以上相同元素相邻; 序列内连续 \(2\) 个及以上相同元素相邻的组的个数最多只有 \(1\)。 时间复杂度:\(O(n)\) 对应AC代码 #include<bits/stdc++.h> using namespace std; #define int long long const int N = 1010, inf = 0x3f3f3f3f; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin ...
Practice. A. The Ultimate Square 题意 给定 \(n\) 个方块,第 \(i\) 个方块的宽度为 \(1\),长度为 \(\lceil \frac{i}{2} \rceil\)。选取一些方块横向拼接成一个正方形,输出正方形的最大边长。 思路 显然,当 \(n\) 为奇数的时候,我们一定能将所有方块都用上,拼成一个长为 \(\frac{n + 1}{2}\) 的正方形;当 \(n\) 为偶数的时候,一个大方块将会多出来,而剩余的方块按照奇数的情况处理即可。 时间复杂度:\(O(1)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 10; signed main(){ ios::sync_with_stdio(false); int t, n; cin >> t; while(t --){ cin >> ...
Practice. A. Yes-Yes? 题意 给定一个字符串,判断其是否是 \(YESYESYES...\) 的连续子串。 思路 判断多出的前缀是否满足条件,若满足条件,以 \(3\) 个字符为一组匹配 \(YES\)。剩余的后缀特判即可。 时间复杂度:\(O(n)\) 对应AC代码 #include<bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while(t --){ int n; string s; cin >> s; n = (int) s.size(); int i = 0; if(s[i] != 'Y'){ if(s[i] ...
Practice A. Medium Number 题意 给定三个数,输出中位数。 思路 排序,输出中间的。 时间复杂度:\(O(1)\) (确信) 对应AC代码 #include<bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while(t --){ int a[3]; for(int i=0;i<3;i++) cin >> a[i]; sort(a, a + 3); cout << a[1] << '\n'; } return 0; } 过于打卡 B. Atilla's Favorite Problem 题意 给定 ...
Practice. A. SSeeeeiinngg DDoouubbllee 题意 给定一个字符串,将字符串复制一遍后拼接在一起得到一个新的字符串,将该字符串重新组合,输出一种回文组合。 思路 倒着拼到末尾。 时间复杂度:\(O(n)\) 对应AC代码 import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t -- > 0){ String s = scanner.next(); System.out.println(s + new StringBuilder(s).reverse()); } } } 过于无脑 ...
Practice. 代码略去了快读模板 A. Add Plus Minus Sign 题意 给定一个长度为 \(n\) 的二进制字符串,输出 \(n-1\) 个加减运算符,满足最后的结果的绝对值最小。 思路 无视第一位,配对 \(1,1\),对每一对输出 \(-,+\),剩余的 \(1\) 输出 \(-\),剩余的 \(0\) 输出任意符号。 时间复杂度:\(O(n)\) 对应AC代码 import java.io.*; import java.math.*; import java.util.*; import java.util.concurrent.atomic.*; public class Main{ public static void main(String[] args) throws Exception{ Console console = new Console(); int t = console.nextInt(); while(t -- > 0) ...
Practice. A. Extremely Round 题意 给定一个整数 \(n\),输出 \([1,n]\) 内只有一位非 \(0\) 的数的个数。 思路 显然,对于 \(t\) 位,有 \(9\) 个满足要求的数,我们只需考虑到何时停下枚举即可。 时间复杂度:\(O(\log_{10} n)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while(t --){ int n; cin >> n; int a = n, tot = 0; while(a >= 10) a /= 10, tot ++; cout << tot * ...
Contestant(alt). Rank 6738. Rating -86 (+414 -500). A. Yet Another Promotion 题意 定义两天内提供购物服务,每天的货物价格分别为 \(a, b\),在第一天存在促销活动,购买 \(m\) 个货物后会赠送一个。输出购买 \(n\) 个货物的最少花费。 思路 对于 \(m+1\) 个所需货物,$m a $ 和 \((m + 1) \times b\) 分别为第一天和第二天的价格,那么我们只需分类讨论即可: 前者小,那么我们将能参与促销的货物全都在第一天购买,也就是总共有 \(\lfloor \frac{n}{m + 1} \rfloor \times m\) 个货物是参与了促销。此时,我们得到了 \(\lfloor \frac{n}{m + 1} \rfloor \times (m + 1)\) 个货物,那么剩余的货物就作为正常购买,我们用 \(\min(a,b)\) 购买即可; 后者小,直接全都在第二天买即可。 时间复杂度:\(O(1)\) 对应AC代码 #incl ...