题意理解与思路

一道非常易错的题目

题目的要求是让我们找到 $12:00$ 到 $增加 n 分钟$ 内的所有“等差时间”

难点就在于

  • 是从 12 点开始
  • 时间可以很长很长,有多次出现相同的等差时间
  • 不能用遍历,因为会超时,所以要预处理出1~12小时中所有的等差时间
  • 怎么搞好里面的映射关系?

要注意,将预处理出的等差时间转化成分钟(好计算)后,存入数组,映射到从12点开始
同时在离线遍历查询值的时候记得别忘记轮数

总体难度:上位橙~下位黄(易错)

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

string to02(int x) {
if (x < 10)
return "0" + to_string(x);
return to_string(x);
}

bool ischa(string s) {
int n = s.size();
vector<int> a(n);
for (int i = 0; i < n; i++) {
a[i] = s[i] - '0';
}
int cha = a[1] - a[0];
for (int i = 2; i < n; i++) {
if (a[i] - a[i - 1] != cha) {
return false;
}
}
return true;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
vector<int> task(T);
for (int i = 0; i < T; i++) {
cin >> task[i];
}
vector<int> re;
for (int h = 1; h <= 12; h++) {
for (int m = 0; m < 60; m++) {
string t = to_string(h) + to02(m);
if (ischa(t)) {
int offset = (h % 12) * 60 + m;
re.push_back(offset);
}
}
}
for (int k = 0; k < T; k++) {
int ful = task[k] / 720;
int rem = task[k] % 720;
int cnt = 0;
for (int i = 0; i < re.size(); i++) {
if (rem >= re[i]) {
cnt++;
}
}
cout << cnt + ful * re.size() << endl;
}
return 0;
}