目录
A - Checking the Calendar
题目链接https://codeforces.com/problemset/problem/724/A
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
string s[] = { "","monday","tuesday","wednesday","thursday","friday","saturday","sunday" };
string s1, s2;
int ok(int x, int y);
int main()
{
IOS;
cin >> s1 >> s2;
int m1, m2;
for (int i = 1; i <= 7; i++) {
if (s1 == s[i]) m1 = i;
if (s2 == s[i]) m2 = i;
}
if (ok(m1, m2)) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
int ok(int x, int y)
{
int p = x;
p = (p + 31) % 7;
if (!p) p = 7;
if (p == y) return 1;
p = x; p = (p + 30) % 7;
if (!p) p = 7;
if (p == y) return 1;
p = x; p = (p + 28) % 7;
if (!p) p = 7;
if (p == y) return 1;
return 0;
}
B - Batch Sort
题目链接https://codeforces.com/problemset/problem/724/B
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ll long long
const int mac = 2e5 + 10;
const ll inf = 1e16 + 10;
int b[mac];
int a[3100][3100], n, m;
int check();
int main()
{
IOS;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
if (check()) {
cout << "YES" << endl;
return 0;
}
for (int i = 1; i <= m; i++) {
for (int j = i + 1; j <= m; j++) {
for (int k = 1; k <= n; k++) swap(a[k][i], a[k][j]);
if (check()) {
cout << "YES" << endl;
return 0;
}
for (int k = 1; k <= n; k++) swap(a[k][i], a[k][j]);
}
}
cout << "NO" << endl;
return 0;
}
int check()
{
for (int i = 1; i <= n; i++) {
int p = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] != j) p++;
if (p > 2) return 0;
}
}
return 1;
}
C - Ray Tracing
题目链接https://codeforces.com/problemset/problem/724/C
D - Interview with Oleg
题目链接https://codeforces.com/problemset/problem/729/A
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
char ss[400];
int mk[400], flag = 0;
int main()
{
IOS;
int n, m, k;
cin >> n;
cin >> ss;
int head = 0, tail = -1;
for (int i = 0; i < n; i++) {
head = i;
flag = 0;
while (ss[i] == 'o' && ss[i + 1] == 'g' && ss[i + 2] == 'o') {
if (!flag) flag=1,mk[i] = 1;
i += 2;
tail = i;
}
for (int j = head; j <= tail; j++) ss[j] = '+';
}
for (int i = 0; i < n; i++) {
if (mk[i]) {
cout << "***";
}
if (ss[i]!='+') cout << ss[i];
}
return 0;
}
E - Spotlights
题目链接https://codeforces.com/problemset/problem/729/B
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
const int mac = 1e3 + 10;
char ss[400];
int mk[400], flag = 0;
int a[mac][mac], mp[mac][mac][5];//上、左、下、右
int main()
{
IOS;
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == 0) mp[i][j][1] = mp[i - 1][j][1], mp[i][j][2] = mp[i][j - 1][2];
else mp[i][j][1] = mp[i - 1][j][1] + 1, mp[i][j][2] = mp[i][j - 1][2] + 1;
}
}
for (int i = n; i >= 1; i--) {
for (int j = m; j >= 1; j--) {
if (a[i][j] == 0) mp[i][j][3] = mp[i + 1][j][3], mp[i][j][4] = mp[i][j + 1][4];
else mp[i][j][3] = mp[i + 1][j][3] + 1, mp[i][j][4] = mp[i][j + 1][4] + 1;
}
}
int ans = 0;
for (int i=1; i<=n; i++)
for (int j = 1; j <= m; j++) {
if (a[i][j] == 0) {
if (mp[i][j][1]) ans++;
if (mp[i][j][2]) ans++;
if (mp[i][j][3]) ans++;
if (mp[i][j][4]) ans++;
}
}
cout << ans << endl;
return 0;
}
F - Road to Cinema
题目链接https://codeforces.com/problemset/problem/729/C
#include <bits/stdc++.h>
using namespace std;
const int mac = 2e5 + 10;
#define IOS ios::sync_with_stdio(false)
#define ll long long
const ll inf = 2e15 + 10;
struct node
{
int price, tank;
}a[mac];
ll b[mac], k;
ll tot = 0;
int ok(ll x);
int main()
{
IOS;
ll n, s;
cin >> n >> k >> s >> tot;
for (int i = 1; i <= n; i++) {
cin >> a[i].price >> a[i].tank;
}
for (int i = 1; i <= k; i++) cin >> b[i];
sort(b + 1, b + 1 + k);
b[0] = 0; b[k + 1] = s;
ll l = 0, r = s * 2, mid = 0, ans = inf;
while (l <= r) {
mid = (l + r) >> 1;
if (ok(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
if (ans == inf) {
cout << -1 << endl; return 0;
}
ll ans1 = inf;
for (int i = 1; i <= n; i++) {
if (a[i].tank >= ans && a[i].price < ans1) ans1 = a[i].price;
}
if (ans1 == inf) cout << -1 << endl;
else cout << ans1 << endl;
return 0;
}
int ok(ll x)
{
ll tt = 0;
for (int i = 1; i <= k + 1; i++) {
ll dis = b[i] - b[i - 1];
if (dis > x) return 0;
else if (dis * 2 <= x) tt += dis;
else tt += dis * 3ll - x;
if (tt > tot) return 0;
}
return 1;
}