A.Buses Between Cities(Codeforces 665A)
思路
假设主角的车在
s
时刻出发,在t时刻到达。那么在这个时间段内在道路上出现过的由B驶来的车辆的数量
(另外,因为数据规模较小,用模拟的方法貌似也可以做)
代码
#include <cstdio>
const int first = 5 * 60, final = 23 * 60 + 59;
int fa, ta, fb, tb, h, m, s, t, x, y;
int main() {
scanf("%d%d%d%d%d:%d", &fa, &ta, &fb, &tb, &h, &m);
s = 60 * h + m - first;
t = s + ta;
if(t <= final - first) {
x = t / fb + (t % fb != 0);
}
else {
x = (final - first) / fb + 1;
}
y = s < tb ? 0 : (s - tb) / fb + 1;
printf("%d\n", x - y);
return 0;
}
B. Shopping(Codeforces 665B)
思路
因为数据规模比较小,所以可以直接模拟(数组或双端队列)。
代码
#include <bits/stdc++.h>
using namespace std;
int n, m, k, item, ans;
deque <int> :: iterator it;
deque <int> d;
int main() {
cin >> n >> m >> k;
while(k--) {
cin >> item;
d.push_back(item);
}
ans = 0;
for(int i = 0; i < n * m; i++) {
cin >> item;
for(it = d.begin(); it != d.end(); it++) {
ans++;
if(*it != item) {
continue;
}
d.erase(it);
break;
}
d.push_front(item);
}
cout << ans << endl;
return 0;
}
C. Simple Strings(Codeforces 655C)
思路
首先从题目给的数据量来看,题目给的时间似乎只够设计
代码
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int n;
int main() {
scanf("%s", s);
n = strlen(s);
for(int i = 1; i < n; i++) {
if(s[i] == s[i-1]) {
s[i] = (s[i] - 'a' + 1) % 26 + 'a';
if(i + 1 < n && s[i] == s[i+1]) {
s[i] = (s[i] - 'a' + 1) % 26 + 'a';
}
}
}
printf("%s\n", s);
return 0;
}
(其它题目略)