TEST 9
A. 三人三数
- 比一下就好了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23signed main() {
IOS;
int ans = 0;
int n, a, b, c, d, e, f;
cin >> n >> a >> b >> c >> d >> e >> f;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
if (ch(a, i) <= 2 && ch(b, j) <= 2 && ch(c, k) <= 2) {
ans++;
continue;
}
if (ch(d, i) <= 2 && ch(e, j) <= 2 && ch(f, k) <= 2)
{
ans++;
}
}
}
}
cout << ans << endl;
return 0;
}
B. 最后派对
- 模拟写一下就好了
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
37struct node {
int v, w;
};
bool cmp(node a, node b) {
if ((a.v + a.w) == (b.v + b.w)) {
return a.v < b.v;
}
return (a.v + a.w) < (b.v + b.w);
}
signed main()
{
IOS;
int n, m;
cin >> n >> m;
vector<node> t(n + 1);
for (int i = 1; i <= n; i++) {
cin >> t[i].v >> t[i].w;
}
sort(t.begin() + 1, t.end(), cmp);
int sum = 0;
for (int i = 1; i <= n; i++) {
int tmp = t[i].w + t[i].v;
if (sum + tmp <= m) {
sum += tmp;
}
else if(sum + t[i].v / 2 + t[i].w <= m) {
cout << i << endl;
return 0;
}
else {
cout << i - 1 << endl;
return 0;
}
}
cout << n << endl;
return 0;
}
C. 边走边种
- 离散化,找好边界
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
42int n;
int L[MAX], R[MAX];
int idx;
vector<int> v;
signed main()
{
IOS;
cin >> n;
for (int i = 1; i <= n; i++)
{
int x;
char c;
cin >> x >> c;
int tmp = c == 'R' ? idx + x : idx - x;
L[i] = min(tmp, idx) + 1, R[i] = max(tmp, idx);
v.push_back(L[i]), v.push_back(R[i] + 1);
idx = tmp;
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
vector<int> len(v.size() + 1);
for (int i = 1; i <= n; i++)
{
L[i] = lower_bound(v.begin(), v.end(), L[i]) - v.begin();
R[i] = lower_bound(v.begin(), v.end(), R[i] + 1) - v.begin();
len[L[i]]++, len[R[i]]--;
}
int ans = 0;
for (int i = 0; i < v.size(); i++)
{
if (i) len[i] += len[i - 1];
if (len[i] >= 2)
{
ans += v[i + 1] - v[i];
}
}
cout << ans << endl;
return 0;
}
D. 可爱序列
- 取模做好DP就好了
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
// vector<int> q[MAX];
int idx[MAX];
int DP[MAX];
signed main()
{
IOS;
// cout << 5 % 1 << endl;
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
x %= m;
int tmp = m - x;
tmp %= m;
DP[i] = idx[tmp] + 1;
idx[x] = max(idx[x], DP[i]);
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
// cout << DP[i] << endl;
ans = max(ans, DP[i]);
}
cout << n - ans << endl;
return 0;
}
E. 立方方方
- 很经典的莫队题,只要能增删一个数并且可以离线操作就可以莫队
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
int n, s, q, a, l, r;
vector<int> p;
vector<int> ep[MAX];
struct node
{
int uid, l, r;
} ans[MAX];
bool cmp(const node A, const node B)
{
if (A.l / s != B.l / s)
return A.l / s < B.l / s;
return ((A.l / s) & 1) ? A.r < B.r : A.r > B.r;//不这么写会T
}
int now = 0, cnt[MAX], res[MAX];
bool isprime[MAX];
void add(int x)
{
for (int &i : ep[x])
{
int t = ++cnt[i] % 3;
if (t == 1)
now++;
if (t == 0)
now--;
}
}
void del(int x)
{
for (int &i : ep[x])
{
int t = --cnt[i] % 3;
if (t == 2)
now++;
if (t == 0)
now--;
}
}
signed main()
{
IOS;
for (int i = 2; i <= 1000; i++)
{
if (!isprime[i])
{
for (int j = i * 2; j <= 1000; j += i)
{
isprime[j] = 1;
}
p.push_back(i);
}
}
cin >> n >> q;
s = max(1ll, (ll)sqrt((ll)n * n / q));
for (int i = 1; i <= n; i++)
{
cin >> a;
for (int j : p)
{
while (a % j == 0)
{
ep[i].push_back(j);
a /= j;
}
if (a == 1)
break;
}
if (a > 1)
ep[i].push_back(a);
}
for (int i = 1; i <= q; i++)
{
cin >> ans[i].l >> ans[i].r;
ans[i].uid = i;
}
sort(ans + 1, ans + 1 + q, cmp);
int l = 0, r = -1;
for (int i = 1; i <= q; i++)
{
while (r < ans[i].r)
add(++r);
while (l > ans[i].l)
add(--l);
while (r > ans[i].r)
del(r--);
while (l < ans[i].l)
del(l++);
res[ans[i].uid] = now;
}
for (int i = 1; i <= q; i++)
{
if (res[i])
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Ysmmm的快乐小屋!