AtCoder Beginner Contest 350 (ABCDEF题)视频讲解

这篇具有很好参考价值的文章主要介绍了AtCoder Beginner Contest 350 (ABCDEF题)视频讲解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

A - Past ABCs

Problem Statement

You are given a string S S S of length 6 6 6. It is guaranteed that the first three characters of S S S are ABC and the last three characters are digits.
Determine if S S S is the abbreviation of a contest held and concluded on AtCoder before the start of this contest.
Here, a string T T T is “the abbreviation of a contest held and concluded on AtCoder before the start of this contest” if and only if it equals one of the following 348 348 348 strings:
ABC001, ABC002, … \ldots , ABC314, ABC315, ABC317, ABC318, … \ldots , ABC348, ABC349.
Note that ABC316 is not included.

Constraints

S S S is a string of length 6 6 6 where the first three characters are ABC and the last three characters are digits.

Input

The input is given from Standard Input in the following format:

S S S

Output

If S S S is the abbreviation of a contest held and concluded on AtCoder before the start of this contest, print Yes; otherwise, print No.

Sample Input 1

ABC349

Sample Output 1

Yes

ABC349 is the abbreviation of a contest held and concluded on AtCoder last week.

Sample Input 2

ABC350

Sample Output 2

No

ABC350 is this contest, which has not concluded yet.

Sample Input 3

ABC316

Sample Output 3

No

ABC316 was not held on AtCoder.

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	string s;
	cin >> s;

	s.erase(0, 3);

	if (stoi(s) < 350 && s != "316" && s != "000") cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

B - Dentist Aoki

Problem Statement

Takahashi has N N N teeth, one in each of the holes numbered 1 , 2 , … , N 1, 2, \dots, N 1,2,,N.

Dentist Aoki will perform Q Q Q treatments on these teeth and holes.

In the i i i-th treatment, hole T i T_i Ti is treated as follows:
If there is a tooth in hole T i T_i Ti, remove the tooth from hole T i T_i Ti.
If there is no tooth in hole T i T_i Ti (i.e., the hole is empty), grow a tooth in hole T i T_i Ti.
After all treatments are completed, how many teeth does Takahashi have?

Constraints

All input values are integers.
1 ≤ N , Q ≤ 1000 1 \le N, Q \le 1000 1N,Q1000
1 ≤ T i ≤ N 1 \le T_i \le N 1TiN

Input

The input is given from Standard Input in the following format:

N N N Q Q Q
T 1 T_1 T1 T 2 T_2 T2 … \dots T Q T_Q TQ

Output

Print the number of teeth as an integer.

Sample Input 1

30 6
2 9 18 27 18 9

Sample Output 1

28

Initially, Takahashi has 30 30 30 teeth, and Aoki performs six treatments.
In the first treatment, hole 2 2 2 is treated. There is a tooth in hole 2 2 2, so it is removed.
In the second treatment, hole 9 9 9 is treated. There is a tooth in hole 9 9 9, so it is removed.
In the third treatment, hole 18 18 18 is treated. There is a tooth in hole 18 18 18, so it is removed.
In the fourth treatment, hole 27 27 27 is treated. There is a tooth in hole 27 27 27, so it is removed.
In the fifth treatment, hole 18 18 18 is treated. There is no tooth in hole 18 18 18, so a tooth is grown.
In the sixth treatment, hole 9 9 9 is treated. There is no tooth in hole 9 9 9, so a tooth is grown.
The final count of teeth is 28 28 28.

Sample Input 2

1 7
1 1 1 1 1 1 1

Sample Output 2

0

Sample Input 3

9 20
9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8

Sample Output 3

5

Solution

具体见文末视频。

Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 1e3 + 10;

int n, q;
int cnt[N];

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	cin >> n >> q;

	for (int i = 1; i <= n; i ++)
		cnt[i] = 1;
	while (q --) {
		int tooth;
		cin >> tooth;

		cnt[tooth] ^= 1;
	}

	int res = 0;
	for (int i = 1; i <= n; i ++)
		res += cnt[i];

	cout << res << endl;

	return 0;
}

C - Sort

Problem Statement

You are given a permutation A = ( A 1 , … , A N ) A=(A_1,\ldots,A_N) A=(A1,,AN) of ( 1 , 2 , … , N ) (1,2,\ldots,N) (1,2,,N).

Transform A A A into ( 1 , 2 , … , N ) (1,2,\ldots,N) (1,2,,N) by performing the following operation between 0 0 0 and N − 1 N-1 N1 times, inclusive:
Operation: Choose any pair of integers ( i , j ) (i,j) (i,j) such that KaTeX parse error: Expected 'EOF', got '&' at position 9: 1\leq i &̲lt; j \leq N. Swap the elements at the i i i-th and j j j-th positions of A A A.
It can be proved that under the given constraints, it is always possible to transform A A A into ( 1 , 2 , … , N ) (1,2,\ldots,N) (1,2,,N).

Constraints

2 ≤ N ≤ 2 × 1 0 5 2 \leq N \leq 2\times 10^5 2N2×105
( A 1 , … , A N ) (A_1,\ldots,A_N) (A1,,AN) is a permutation of ( 1 , 2 , … , N ) (1,2,\ldots,N) (1,2,,N).
All input values are integers.

Input

The input is given from Standard Input in the following format:

N N N
A 1 A_1 A1 … \ldots A N A_N AN

Output

Let K K K be the number of operations. Print K + 1 K+1 K+1 lines.

The first line should contain K K K.

The ( l + 1 ) (l+1) (l+1)-th line ( 1 ≤ l ≤ K 1\leq l \leq K 1lK) should contain the integers i i i and j j j chosen for the l l l-th operation, separated by a space.

Any output that satisfies the conditions in the problem statement will be considered correct.

Sample Input 1

5
3 4 1 2 5

Sample Output 1

2
1 3
2 4

The operations change the sequence as follows:
Initially, A = ( 3 , 4 , 1 , 2 , 5 ) A=(3,4,1,2,5) A=(3,4,1,2,5).
The first operation swaps the first and third elements, making A = ( 1 , 4 , 3 , 2 , 5 ) A=(1,4,3,2,5) A=(1,4,3,2,5).
The second operation swaps the second and fourth elements, making A = ( 1 , 2 , 3 , 4 , 5 ) A=(1,2,3,4,5) A=(1,2,3,4,5).
Other outputs such as the following are also considered correct:

4
2 3
3 4
1 2
2 3

Sample Input 2

4
1 2 3 4

Sample Output 2

0

Sample Input 3

3
3 1 2

Sample Output 3

2
1 2
2 3

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 2e5 + 10;

int n;
int a[N], p[N];

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	cin >> n;

	for (int i = 1; i <= n; i ++)
		cin >> a[i], p[a[i]] = i;

	std::vector<PII> res;
	for (int i = 1; i <= n; i ++) {
		if (p[i] == i) continue;
		res.emplace_back(i, p[i]);
		int pos = p[i];
		swap(p[i], p[a[i]]), swap(a[i], a[pos]);
	}

	cout << res.size() << endl;
	for (auto v : res)
		cout << v.fi << " " << v.se << endl;

	return 0;
}

D - New Friends

Problem Statement

There is an SNS used by N N N users, labeled with numbers from 1 1 1 to N N N.
In this SNS, two users can become friends with each other.

Friendship is bidirectional; if user X is a friend of user Y, user Y is always a friend of user X.
Currently, there are M M M pairs of friendships on the SNS, with the i i i-th pair consisting of users A i A_i Ai and B i B_i Bi.
Determine the maximum number of times the following operation can be performed:
Operation: Choose three users X, Y, and Z such that X and Y are friends, Y and Z are friends, but X and Z are not. Make X and Z friends.

Constraints

2 ≤ N ≤ 2 × 1 0 5 2 \leq N \leq 2 \times 10^5 2N2×105
0 ≤ M ≤ 2 × 1 0 5 0 \leq M \leq 2 \times 10^5 0M2×105
KaTeX parse error: Expected 'EOF', got '&' at position 12: 1 \leq A_i &̲lt; B_i \leq N
The pairs ( A i , B i ) (A_i, B_i) (Ai,Bi) are distinct.
All input values are integers.

Input

The input is given from Standard Input in the following format:

N N N M M M
A 1 A_1 A1 B 1 B_1 B1
⋮ \vdots
A M A_M AM B M B_M BM

Output

Print the answer.

Sample Input 1

4 3
1 2
2 3
1 4

Sample Output 1

3

Three new friendships with a friend’s friend can occur as follows:
User 1 1 1 becomes friends with user 3 3 3, who is a friend of their friend (user 2 2 2)
User 3 3 3 becomes friends with user 4 4 4, who is a friend of their friend (user 1 1 1)
User 2 2 2 becomes friends with user 4 4 4, who is a friend of their friend (user 1 1 1)
There will not be four or more new friendships.

Sample Input 2

3 0

Sample Output 2

0

If there are no initial friendships, no new friendships can occur.

Sample Input 3

10 8
1 2
2 3
3 4
4 5
6 7
7 8
8 9
9 10

Sample Output 3

12

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 2e5 + 10;

int n, m;
int p[N], sz[N], cnt[N];

int find(int x) {
	if (p[x] != x) p[x] = find(p[x]);
	return p[x];
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	cin >> n >> m;

	for (int i = 1; i <= n; i ++)
		p[i] = i, sz[i] = 1;

	for (int i = 1; i <= m; i ++) {
		int u, v;
		cin >> u >> v;
		int f1 = find(u), f2 = find(v);
		if (f1 == f2) {
			cnt[f1] ++;
		} else {
			p[f1] = f2;
			sz[f2] += sz[f1];
			cnt[f2] += cnt[f1];
		}
	}

	int res = 0;
	for (int i = 1; i <= n; i ++)
		if (find(i) == i) {
			res += sz[i] * (sz[i] - 1) / 2 - sz[i] + 1 - cnt[i];
		}

	cout << res << endl;

	return 0;
}

E - Toward 0

Problem Statement

You are given an integer N N N. You can perform the following two types of operations:
Pay X X X yen to replace N N N with ⌊ N A ⌋ \displaystyle\left\lfloor\frac{N}{A}\right\rfloor AN.
Pay Y Y Y yen to roll a die (dice) that shows an integer between 1 1 1 and 6 6 6, inclusive, with equal probability. Let b b b be the outcome of the die, and replace N N N with ⌊ N b ⌋ \displaystyle\left\lfloor\frac{N}{b}\right\rfloor bN.
Here, ⌊ s ⌋ \lfloor s \rfloor s denotes the greatest integer less than or equal to s s s. For example, ⌊ 3 ⌋ = 3 \lfloor 3 \rfloor=3 3=3 and ⌊ 2.5 ⌋ = 2 \lfloor 2.5 \rfloor=2 2.5=2.
Determine the minimum expected cost paid before N N N becomes 0 0 0 when optimally choosing operations.

The outcome of the die in each operation is independent of other rolls, and the choice of operation can be made after observing the results of the previous operations.

Constraints

1 ≤ N ≤ 1 0 18 1 \leq N \leq 10^{18} 1N1018
2 ≤ A ≤ 6 2 \leq A \leq 6 2A6
1 ≤ X , Y ≤ 1 0 9 1 \leq X, Y \leq 10^9 1X,Y109
All input values are integers.

Input

The input is given from Standard Input in the following format:

N N N A A A X X X Y Y Y

Output

Print the answer.

Your output will be considered correct if the absolute or relative error from the true answer is at most 1 0 − 6 10^{-6} 106.

Sample Input 1

3 2 10 20

Sample Output 1

20.000000000000000

The available operations are as follows:
Pay 10 10 10 yen. Replace N N N with ⌊ N 2 ⌋ \displaystyle\left\lfloor\frac{N}{2}\right\rfloor 2N.
Pay 20 20 20 yen. Roll a die. Let b b b be the outcome, and replace N N N with ⌊ N b ⌋ \displaystyle\left\lfloor\frac{N}{b}\right\rfloor bN.
The optimal strategy is to perform the first operation twice.

Sample Input 2

3 2 20 20

Sample Output 2

32.000000000000000

The available operations are as follows:
Pay 20 20 20 yen. Replace N N N with ⌊ N 2 ⌋ \displaystyle\left\lfloor\frac{N}{2}\right\rfloor 2N.
Pay 20 20 20 yen. Roll a die. Let b b b be the outcome, and replace N N N with ⌊ N b ⌋ \displaystyle\left\lfloor\frac{N}{b}\right\rfloor bN.
The optimal strategy is as follows:
First, perform the second operation to roll the die.
If the outcome is 4 4 4 or greater, then N N N becomes 0 0 0.
If the outcome is 2 2 2 or 3 3 3, then N N N becomes 1 1 1. Now, perform the first operation to make N = 0 N = 0 N=0.
If the outcome is 1 1 1, restart from the beginning.

Sample Input 3

314159265358979323 4 223606797 173205080

Sample Output 3

6418410657.7408381

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

int n, a, x, y;
unordered_map<int, double> f;

double DP(int m) {
	if (!m) return 0;
	if (f.count(m)) return f[m];

	double sum = y;
	for (int i = 2; i <= 6; i ++)
		sum += DP(m / i) + y;
	sum /= 5;
	f[m] = min(sum, DP(m / a) + x);

	return f[m];
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	cin >> n >> a >> x >> y;

	printf("%.8lf\n", DP(n));

	return 0;
}

F - Transpose

Problem Statement

You are given a string S = S 1 S 2 S 3 … S ∣ S ∣ S = S_1 S_2 S_3 \dots S_{|S|} S=S1S2S3SS consisting of uppercase and lowercase English letters, (, and ).

The parentheses in the string S S S are properly matched.
Repeat the following operation until no more operations can be performed:
First, select one pair of integers ( l , r ) (l, r) (l,r) that satisfies all of the following conditions:
KaTeX parse error: Expected 'EOF', got '&' at position 3: l &̲lt; r
S l = S_l = Sl= (
S r = S_r = Sr= )
Each of the characters S l + 1 , S l + 2 , … , S r − 1 S_{l+1}, S_{l+2}, \dots, S_{r-1} Sl+1,Sl+2,,Sr1 is an uppercase or lowercase English letter.
Let T = S r − 1 S r − 2 … S l + 1 ‾ T = \overline{S_{r-1} S_{r-2} \dots S_{l+1}} T=Sr1Sr2Sl+1.
Here, x ‾ \overline{x} x denotes the string obtained by toggling the case of each character in x x x (uppercase to lowercase and vice versa).
Then, delete the l l l-th through r r r-th characters of S S S and insert T T T at the position where the deletion occurred.
Refer to the sample inputs and outputs for clarification.
It can be proved that it is possible to remove all (s and )s from the string using the above operations, and the final string is independent of how and in what order the operations are performed.

Determine the final string.

What does it mean that the parentheses in $S$ are properly matched? First, a correct parenthesis sequence is defined as follows: A correct parenthesis sequence is a string that satisfies one of the following conditions: It is an empty string. There exists a correct parenthesis sequence $A$, and the string is formed by concatenating (, $A$, ) in this order. There exist non-empty correct parenthesis sequences $A$ and $B$, and the string is formed by concatenating $A$ and $B$ in this order. The parentheses in $S$ are properly matched if and only if the (s and )s extracted from $S$ without changing the order form a correct parenthesis sequence. ## Constraints

1 ≤ ∣ S ∣ ≤ 5 × 1 0 5 1 \le |S| \le 5 \times 10^5 1S5×105
S S S consists of uppercase and lowercase English letters, (, and ).
The parentheses in S S S are properly matched.

Input

The input is given from Standard Input in the following format:

S S S

Output

Print the final string.

Sample Input 1

((A)y)x

Sample Output 1

YAx

Let us perform the operations for S = S = S= ((A)y)x.
Choose l = 2 l=2 l=2 and r = 4 r=4 r=4. The substring (A) is removed and replaced with a.
After this operation, S = S = S= (ay)x.
Choose l = 1 l=1 l=1 and r = 4 r=4 r=4. The substring (ay) is removed and replaced with YA.
After this operation, S = S = S= YAx.
After removing the parentheses, the string becomes YAx, which should be printed.

Sample Input 2

((XYZ)n(X(y)Z))

Sample Output 2

XYZNXYZ

Let us perform the operations for S = S = S= ((XYZ)n(X(y)Z)).
Choose l = 10 l=10 l=10 and r = 12 r=12 r=12. The substring (y) is removed and replaced with Y.
After this operation, S = S = S= ((XYZ)n(XYZ)).
Choose l = 2 l=2 l=2 and r = 6 r=6 r=6. The substring (XYZ) is removed and replaced with zyx.
After this operation, S = S = S= (zyxn(XYZ)).
Choose l = 6 l=6 l=6 and r = 10 r=10 r=10. The substring (XYZ) is removed and replaced with zyx.
After this operation, S = S = S= (zyxnzyx).
Choose l = 1 l=1 l=1 and r = 9 r=9 r=9. The substring (zyxnzyx) is removed and replaced with XYZNXYZ.
After this operation, S = S = S= XYZNXYZ.
After removing the parentheses, the string becomes XYZNXYZ, which should be printed.

Sample Input 3

(((()))(()))(())

Sample Output 3


The final outcome may be an empty string.

Sample Input 4

dF(qT(plC())NnnfR(GsdccC))PO()KjsiI((ysA)eWW)ve

Sample Output 4

dFGsdccCrFNNnplCtQPOKjsiIwwEysAve

Solution

后期补一下这题目的视频


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 5e5 + 10;

int n;
string s, tmp, ans = " ";
struct Splay {
    int s[2], p, val;
    int sz, flg;
    void init(int _val, int _p) { p = _p, val = _val, sz = 1; }
}tr[N];
int root, idx;

void pushup(int u) {
    tr[u].sz = tr[tr[u].s[0]].sz + 1 + tr[tr[u].s[1]].sz;
}
void pushdown(int u) {
    if (tr[u].flg) {
        swap(tr[u].s[0], tr[u].s[1]);
        tr[tr[u].s[0]].flg ^= 1;
        tr[tr[u].s[1]].flg ^= 1;
        tr[u].flg = 0;
    }
}
void rotate(int x) {
    int y = tr[x].p, z = tr[y].p;
    int k = tr[y].s[1] == x;
    tr[x].p = z, tr[z].s[tr[z].s[1] == y] = x;
    tr[y].s[k] = tr[x].s[k ^ 1], tr[tr[x].s[k ^ 1]].p = y;
    tr[x].s[k ^ 1] = y, tr[y].p = x;
    pushup(y), pushup(x);
}
void splay(int x, int k) {
    while (tr[x].p != k) {
        int y = tr[x].p, z = tr[y].p;
        if (z != k) {
            if ((tr[z].s[0] == y) ^ (tr[y].s[0] == x)) rotate(x);
            else rotate(y);
        }
        rotate(x);
    }
    if (!k) root = x;
}
void insert(int val) {
    int u = root, p = 0;
    while (u) p = u, u = tr[u].s[val > tr[u].val];
    u = ++ idx;
    if (p) tr[p].s[val > tr[p].val] = u;
    tr[u].init(val, p);
    splay(u, 0);
}
int get_k(int k) {
    int u = root;
    while (1) {
        pushdown(u);
        if (tr[tr[u].s[0]].sz >= k) u = tr[u].s[0];
        else if (tr[tr[u].s[0]].sz + 1 == k) return u;
        else k -= tr[tr[u].s[0]].sz + 1, u = tr[u].s[1];
    }
}
void output(int u) {
    pushdown(u);
    if (tr[u].s[0]) output(tr[u].s[0]);
    if (tr[u].val >= 1 && tr[u].val <= n) cout << ans[tr[u].val];
    if (tr[u].s[1]) output(tr[u].s[1]);
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	cin >> s;
	n = s.size(), s = ' ' + s;

	int cnt = 0;
	std::vector<int> l;
	std::vector<PII> seg;
	for (int i = 1; i <= n; i ++) {
		if (s[i] == '(') {
			if (cnt & 1) {
				for (auto &v : tmp)
					if (v >= 'A' && v <= 'Z')
						v = v - 'A' + 'a';
					else
						v = v - 'a' + 'A';
			}
			ans += tmp, tmp.clear();
			l.emplace_back(ans.size());
			cnt ++;
		}
		else if (isalpha(s[i])) {
			tmp += s[i];
		} else {
			if (cnt & 1) {
				for (auto &v : tmp)
					if (v >= 'A' && v <= 'Z')
						v = v - 'A' + 'a';
					else
						v = v - 'a' + 'A';
			}
			ans += tmp, tmp.clear();
			seg.emplace_back(l.back(), ans.size() - 1);
			cnt --, l.pop_back();
		}
	}
	if (tmp.size()) ans += tmp;
	n = ans.size() - 1;

	// for (auto v : seg)
	// 	cout << v.fi << " " << v.se << endl;
	for (int i = 0; i <= n + 1; i ++)
		insert(i);

	for (auto v : seg) {
		int l = v.fi, r = v.se;
		l = get_k(l), r = get_k(r + 2);
		splay(r, 0), splay(l, r);
		tr[tr[l].s[1]].flg ^= 1;
	}

	output(root);

	return 0;
}

视频题解

Atcoder Beginner Contest 350(A ~ F 题)


最后祝大家早日AtCoder Beginner Contest 350 (ABCDEF题)视频讲解,Atcoder,算法,c++文章来源地址https://www.toymoban.com/news/detail-857532.html

到了这里,关于AtCoder Beginner Contest 350 (ABCDEF题)视频讲解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Atcoder Beginner Contest 311 C - E题讲解

    Problem Statement There is a directed graph with N N N vertices and N N N edges. The i i i -th edge goes from vertex i i i to vertex A i A_i A i ​ . (The constraints guarantee that i ≠ A i i neq A_i i  = A i ​ .) Find a directed cycle without the same vertex appearing multiple times. It can be shown that a solution exists under the constraints of t

    2024年02月15日
    浏览(30)
  • AtCoder Beginner Contest 314(A~D题 + G题)讲解

    Problem Statement The number pi to the 100 100 100 -th decimal place is 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 . You are given an integer N N N between 1 1 1 and 100 100 100 , inclusive. Print the value of pi to the N N N -th decimal place. More precisely, truncate the value of pi to N N N decim

    2024年02月13日
    浏览(30)
  • AtCoder Beginner Contest 310

    感觉F又双叒叕写复杂了 点杯咖啡,要 (p) 元,但可以用一个优惠券,使得咖啡只要 (q) 元,但你需要额外购买 (n) 个商品中(价格为 (a_i) )的一个。 问点杯咖啡的最小价格。 考虑直接买还是使用优惠券,使用优惠券的话就选 (n) 个商品中价格最小的。 两种情况取最小

    2024年02月16日
    浏览(28)
  • AtCoder Beginner Contest 320

    给定 (a,b) ,输出 (a^b + b^a) 。 因为数不超过 (10) ,可以直接用 pow 计算然后转成 (int) 。不会有精度损失。 神奇的代码 给定一个字符串 (s) ,求长度最长的回文串。 因为长度只有 (100) ,可以直接枚举子串,然后暴力判断是不是回文串(翻转后是否和自身相同),复杂

    2024年02月08日
    浏览(38)
  • AtCoder Beginner Contest 348

    给定 (n) ,输出 (ooxooxoox...) ,长度为 (n) 。 按题意模拟即可。 神奇的代码 给定 (n) 个点,对每个点,求出与其距离最远的点的下标。 (n) 只有 (100) ,对于每个点,花 (O(n)) 遍历每个点最大化距离,时间复杂度为 (O(n^2)) 。 神奇的代码 (n) 个豌豆,每个豌豆有美味值

    2024年04月08日
    浏览(42)
  • AtCoder Beginner Contest 314

    怎么好多陌生单词 审核怎么这么逆天,半小时还没审完 给定 (pi) 的值以及数 (n) ,要求保留 (n) 位小数输出,不四舍五入。 字符串形式储存然后截取末尾即可。 神奇的代码 (n) 个人玩轮盘赌游戏,简单说就是一个转盘有 (37) 个数字以及一个箭头,箭头会等概率停在某

    2024年02月13日
    浏览(40)
  • AtCoder Beginner Contest 335

    给定一个字符串,将最后一位改成 4 。 模拟即可。 神奇的代码 给定 (n) ,按字典序输出非负整数 (i,j,k) ,使得 (i+j+kleq n) (n) 只有 (21) ,直接 (O(n^3)) 枚举判断即可。 神奇的代码 二维网格,贪吃蛇,移动,进行 (q) 次操作,分两种 指定贪吃蛇下一步移动的方向 指定

    2024年01月19日
    浏览(32)
  • AtCoder Beginner Contest 322

    给定一个字符串,找到最先出现 ABC 的位置。 直接查找判断即可。 神奇的代码 给定字符串 s 和 t ,问 s 是不是 t 的前缀和后缀。 根据前后缀定义判断即可。这里试了下 python 神奇的代码 (n) 天,有 (m) 天会放烟花。 问每一天,距离未来最近的放烟花的天数。 两个双指针一

    2024年02月08日
    浏览(33)
  • AtCoder Beginner Contest 330

    给定 (n) 个学生的分数,以及及格分 (x) ,问多少人及格了。 依次判断即可。 神奇的代码 回答 (n) 个问题,每个问题给定 (a,l,r) ,问函数 (f(x) = |x - a|) 在 ([l,r]) 的最小值。 全定义域下,最小值显然在 (x=a) 取得。绝对值函数图像是 (V) 型。 现在限定在 ([l,r]) ,则

    2024年02月05日
    浏览(116)
  • AtCoder Beginner Contest 318

    咕咕咕,总力战还没打,凹不过卷狗,躺了.jpg 给定 (n, m, p) ,问有多少个 (i) 满足 (0 m+pi leq n) 减去初始的 (m) ,剩下的就是看 (p) 的倍数个数。 神奇的代码 一个二维空间,有 (n) 个矩形覆盖。 问有多大的空间被覆盖了。重复覆盖算一次。 空间大小只有 (100) ,矩形

    2024年02月10日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包