Codeforces Round #707 (Div. 2, based on Moscow Open Olympiad in Informatics)
Problem 1501A. Alexey and Train
按题意,比较到站的最大值.
using ll = long long;int a[105], b[105], c[105];int main() {// ios_base::sync_with_stdio(false), cin.tie(0);int _;for (cin >> _; _--;) {int n, s = 0;scanf("%d", &n);for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);for (int i = 1; i <= n; i++) {scanf("%d", &c[i]), s += a[i] - b[i - 1] + c[i];if (i == n) break;s = max(s + (b[i] - a[i] + 1) / 2, b[i]);}cout << s << "\n";}return 0;}
Problem 1501B. Napoleon Cake
从后往前比较.
int arr[200001];int res[200001];int main() {ios_base::sync_with_stdio(false), cin.tie(0);int _ = 1;for (cin >> _; _--;) {int n, i, mn = 1e9;cin >> n;for (i = 1; i <= n; i++) cin >> arr[i];for (i = n; i >= 1; i--) {mn = min(mn, i - arr[i]);res[i] = (mn < i);}for (i = 1; i <= n; i++) cout << res[i] << " ";cout << endl;}return 0;}
Problem 1501C. Going Home
把两数之和想象成坐标,x 和 y
使用双指针然后存储和存储一下,如果能匹配并且 坐标不重复即可输出。
数组开大点,这个导致WA好几次了….
const int N = 5000003;int x[N], y[N], a[N];int main() {ios_base::sync_with_stdio(false), cin.tie(0);int n;cin >> n;for (int i = 1; i <= n; ++i) cin >> a[i];for (int i = 1; i <= n; ++i)for (int j = i + 1; j <= n; ++j) {int s = a[i] + a[j];if (x[s] && y[s] && x[s] != i && y[s] != j && x[s] != j &&y[s] != i) {cout << "YES\n";cout << i << " " << j << " " << x[s] << " " << y[s] << "\n";return 0;}x[s] = i;y[s] = j;}cout << "NO\n";return 0;}
