比赛链接:Here
A题挺水的就不写了
1304B - Longest Palindrome
题意:
- 输入
个长度为
的字符串,问这些字符串能组成的最长回文串有多长。
思路:
- 贪心的思想,我们只需要用当前字符串以及寻找该字符串的反向串是否存在,如果存在的话,就把该字符串与它的反向串添加进答案串的首尾。
- 注意中间的那个字符串,如果我们输入的字符串中有回文串,且该串的反向串也不存在的话,可以把该串单独放在答案串的中间。
string s[110];map<string, int>mp;bool check(string s) {int n = s.size();for (int i = 0, j = n - 1; i <= n / 2; ++i, j--)if (s[i] != s[j]) return 0;return 1;}int main() {cin.tie(nullptr)->sync_with_stdio(false);int n, m; cin >> n >> m;for (int i = 0; i < n; ++i) cin >> s[i], mp[s[i]] = 1;string ans, z, t;bool f = 0;for (int i = 0; i < n; ++i) {if (check(s[i])) z = s[i], f = 1;else {reverse(s[i].begin(), s[i].end());string tmp = s[i];reverse(s[i].begin(), s[i].end());if (mp[tmp] == 1) {t += tmp;mp[tmp] = 0;}}mp[s[i]] = 0;}ans += t;reverse(t.begin(), t.end());if (f) ans += z;ans += t;cout << int(ans.size()) << "\n";if (int(ans.size()))cout << ans << "\n";}
1304C - Air Conditioner
题意:
- 输入
,再输入
个顾客的信息,分别为客人来的时间,客人需要的温度范围,每分钟可以进行一次三种操作之一:升温,降温和不变。问能否满足所有客人的需求。
思路:
一开始写复杂了,这道题本质就是暴力模拟,要满足所有客人的需求,那么就用当前客人与下一个客人的时间差来取温度的最大(r)和最小值(l),当下一个客人来时再判断这个客人的需求是否在这个[l,r]之内。
int main() {cin.tie(nullptr)->sync_with_stdio(false);int _; for (cin >> _; _--;) {ll n, m;cin >> n >> m;ll t = 0, l = m, r = m;bool f = 1;while (n--) {ll ti, x, y;cin >> ti >> x >> y;l = l - (ti - t), r = r + (ti - t);t = ti;l = max(l, x), r = min(r, y);if (l > r) f = 0;}cout << (f ? "YES\n" : "NO\n");}}
1304D - Shortest and Longest LIS
题意:
- 给定一个
,与构造规则,要求构造出符合构造规则的LIS最小和最大的串
思路:
原本想试试DP,写状态转移发现最短序列的话,对于一串大于号,我们把当前未使用过的比较大的数尽可能的放在左边。最长序列就是反过来,尽可能的放未使用过的小的数放在左边即可
简单来说就是贪心
const int N = 2e5 + 10;ll a[N];int main() {cin.tie(nullptr)->sync_with_stdio(false);int _; for (cin >> _; _--;) {int n; string s;cin >> n >> s;int nn = n, lst = 0;for (int i = 0; i < n; ++i) {if (s[i] == '>' || i == n - 1) {for (int j = i; j >= lst; j--)a[j] = nn--;lst = i + 1;}}for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];nn = 1, lst = 0;for (int i = 0; i < n; ++i) {if (s[i] == '<' || i == n - 1) {for (int j = i; j >= lst; j--) a[j] = nn++;lst = i + 1;}}for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];}}
E,F不会做….明明挺多人都过了QAQ
