文章目录
Codeforces Round #620 (Div. 2)
C. Air Conditioner
题解: 先对顾客到店的时间进行排序,之后对于每一个顾客判断[Li , Ri] 与 [LI - t ,Ri + t] 是否有交集即可
D. Shortest and Longest LIS
题意: 先给你一个数字 t 便是有T 组,然后给了一个N 表示有N个数且是一个全排列,后面跟着N-1个字符,表示一个a[i]和a[i+1]的大小关系,然后让你输出个一构造出的最短和最长的上升子序列。
题解: 贪心。对于LIS尽量短,把大数字尽量放到前面去;反之把小数字尽量放到前面去。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int ans[maxn];
int main() {
int t, n;
cin >> t;
string s;
while (t--) {
cin >> n >> s;
int num = n, las = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '>' || i == n - 1) {
for (int j = i; j >= las; j--) ans[j] = num--;
las = i + 1;
}
}
for (int i = 0; i < n; i++) printf("%d ", ans[i]);
cout << endl;
num = 1, las = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '<' || i == n - 1) {
for (int j = i; j >= las; j--) ans[j] = num++;
las = i + 1;
}
}
for (int i = 0; i < n; i++) printf("%d ", ans[i]);
cout << endl;
}
return 0;
}
E. 1-Trees and Queries
题解: 若s到t路径长度为x,当x<=k且奇偶性相同时则合法。那么我只需要判断三种情况:从s走到t、从s出发先走到x再走到y再走到t、从s出发先走到y再走到x再走到t。其中一种合法即可。