Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 #2

Open
wants to merge 568 commits into
base: master
Choose a base branch
from
Open

1 #2

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
568 commits
Select commit Hold shift + click to select a range
c455971
update
peckfly Apr 9, 2019
edd4fd8
update
peckfly Apr 9, 2019
0183766
update
peckfly Apr 9, 2019
dd0d2dd
update
peckfly Apr 9, 2019
fd75f26
update
peckfly Apr 9, 2019
e73d80d
update
peckfly Apr 9, 2019
2bd87e8
update
peckfly Apr 9, 2019
34a7105
update
peckfly Apr 10, 2019
4752419
update
peckfly Apr 10, 2019
5213452
update
peckfly Apr 10, 2019
a6534dd
update
peckfly Apr 10, 2019
9cc1840
update
peckfly Apr 10, 2019
4bef301
update
peckfly Apr 10, 2019
4fd11f6
update
peckfly Apr 10, 2019
f04d4af
update
peckfly Apr 10, 2019
3ae933e
update
peckfly Apr 10, 2019
9400a3c
update
peckfly Apr 10, 2019
4c4af62
update
peckfly Apr 10, 2019
a3739ca
update
peckfly Apr 10, 2019
97e7014
update
peckfly Apr 10, 2019
e95419d
update
peckfly Apr 10, 2019
8a8a451
update
peckfly Apr 10, 2019
a4cd154
update
peckfly Apr 10, 2019
c1193ec
update
peckfly Apr 10, 2019
3787595
update
peckfly Apr 10, 2019
d44f361
update
peckfly Apr 10, 2019
80cc6b0
update
peckfly Apr 10, 2019
e57a768
update
peckfly Apr 10, 2019
b825e61
update
peckfly Apr 10, 2019
81b0f9e
update
peckfly Apr 10, 2019
15c1da4
update
peckfly Apr 10, 2019
909b69f
update
peckfly Apr 10, 2019
1866c3e
update
peckfly Apr 10, 2019
b7c5a57
update
peckfly Apr 10, 2019
ff37eb2
update
peckfly Apr 10, 2019
340114f
update
peckfly Apr 10, 2019
89a93d7
update
peckfly Apr 10, 2019
5a318fe
update
peckfly Apr 10, 2019
c4d9e2b
update
peckfly Apr 10, 2019
6667aa9
update
peckfly Apr 10, 2019
f1efe4b
update
peckfly Apr 10, 2019
412bb6b
update
peckfly Apr 10, 2019
729d5f2
update
peckfly Apr 10, 2019
1666b97
update
peckfly Apr 10, 2019
db48b47
update
peckfly Apr 11, 2019
afa74d8
update
peckfly Apr 11, 2019
c949fa8
update
peckfly Apr 11, 2019
d120888
update
peckfly Apr 11, 2019
71de056
update
peckfly Apr 11, 2019
bdca2ad
update
peckfly Apr 11, 2019
1e16797
update
peckfly Apr 11, 2019
5147ed4
update
peckfly Apr 11, 2019
d0155d8
update
peckfly Apr 11, 2019
1a8609f
update
peckfly Apr 11, 2019
fbea2c5
update
peckfly Apr 11, 2019
22f3772
update
peckfly Apr 11, 2019
b907edd
update
peckfly Apr 11, 2019
ff9d690
update
peckfly Apr 11, 2019
c166365
update
peckfly Apr 11, 2019
f50b56b
update
peckfly Apr 11, 2019
7be8947
update
peckfly Apr 11, 2019
94d42e1
update
peckfly Apr 11, 2019
922cc67
update
peckfly Apr 11, 2019
496c206
update
peckfly Apr 11, 2019
cd16b52
update
peckfly Apr 11, 2019
a34e1f2
update
peckfly Apr 11, 2019
93b4907
update
peckfly Apr 11, 2019
5e7bfcb
update
peckfly Apr 12, 2019
89344ab
update
peckfly Apr 12, 2019
81e4e4e
update
peckfly Apr 12, 2019
51bee33
update
peckfly Apr 12, 2019
4f82622
update
peckfly Apr 12, 2019
b5372a8
update
peckfly Apr 12, 2019
1253b2f
update
peckfly Apr 12, 2019
9b77720
update
peckfly Apr 12, 2019
a5bd88c
update
peckfly Apr 12, 2019
ffef124
update
peckfly Apr 12, 2019
5ea8a95
update
peckfly Apr 12, 2019
0b8cd70
update
peckfly Apr 12, 2019
6551c96
update
peckfly Apr 12, 2019
b0fa731
update
peckfly Apr 12, 2019
32939ec
update
peckfly Apr 12, 2019
6f20810
update
peckfly Apr 12, 2019
86a7d76
update
peckfly Apr 12, 2019
9b8d84f
update
peckfly Apr 12, 2019
5710114
update
peckfly Apr 12, 2019
09e14e5
update
peckfly Apr 12, 2019
114107f
update
peckfly Apr 12, 2019
b892ad2
update
peckfly Apr 12, 2019
9450aab
update
peckfly Apr 12, 2019
ecd1652
update
peckfly Apr 12, 2019
1c15cdb
update
peckfly Apr 12, 2019
5356861
update
peckfly Apr 12, 2019
aa28e8e
update
peckfly Apr 12, 2019
2872b7b
update
peckfly Apr 12, 2019
852331e
update
peckfly Apr 12, 2019
4f09e50
update
peckfly Apr 12, 2019
ce10b1d
update
peckfly Apr 12, 2019
719fb35
update
peckfly Apr 12, 2019
6e681b4
update
peckfly Apr 12, 2019
b21e764
update
peckfly Apr 12, 2019
3a589a5
update
peckfly Apr 12, 2019
407e1e9
update
peckfly Apr 12, 2019
0b95f5c
update
peckfly Apr 12, 2019
4e6cd3b
update
peckfly Apr 12, 2019
435e62f
update
peckfly Apr 12, 2019
827185d
update
peckfly Apr 12, 2019
ca5c20b
update
peckfly Apr 12, 2019
ac67498
update
peckfly Apr 12, 2019
424b61d
update
peckfly Apr 12, 2019
d7aed52
update
peckfly Apr 12, 2019
79b2902
update
peckfly Apr 12, 2019
67dc4c6
update
peckfly Apr 12, 2019
31aec26
update
peckfly Apr 12, 2019
55c118a
update
peckfly Apr 13, 2019
8fd15a9
update
peckfly Apr 13, 2019
e2063e9
update
peckfly Apr 13, 2019
54e5a45
update
peckfly Apr 13, 2019
7087ddf
update
peckfly Apr 13, 2019
65bf684
update
peckfly Apr 14, 2019
846f962
update
peckfly Apr 14, 2019
f44d372
update
peckfly Apr 14, 2019
2a97497
update
peckfly Apr 14, 2019
aeb48b3
update
peckfly Apr 14, 2019
a181f39
update
peckfly Apr 14, 2019
277adc7
update
peckfly Apr 14, 2019
fe780cd
update
peckfly Apr 15, 2019
cab8af2
update
peckfly Apr 15, 2019
1999e3a
update
peckfly Apr 15, 2019
3ba1004
update
peckfly Apr 15, 2019
75f93d8
update
peckfly Apr 15, 2019
5527756
update
peckfly Apr 16, 2019
a6be9b7
update
peckfly Apr 16, 2019
77a5076
update
peckfly Apr 17, 2019
61c7907
update
peckfly Apr 17, 2019
c069967
update
peckfly Apr 18, 2019
4a6b5fa
update
peckfly Apr 18, 2019
cf22843
update
peckfly Apr 19, 2019
360331d
update
peckfly Apr 19, 2019
389051f
update
peckfly Apr 20, 2019
2e31da3
update
peckfly Apr 20, 2019
ea0dd1c
update
peckfly Apr 25, 2019
6473e84
update
peckfly Apr 25, 2019
d9cce5d
update
peckfly Apr 25, 2019
3581f71
update
peckfly Apr 27, 2019
4101dbf
add
peckfly Apr 30, 2019
18fa824
add
peckfly Apr 30, 2019
5017441
add
peckfly Apr 30, 2019
0dd76c4
add
peckfly Apr 30, 2019
9af2331
update
peckfly May 3, 2019
7db95f2
update
peckfly May 3, 2019
4f39f97
update
peckfly May 4, 2019
028fcec
update
peckfly May 5, 2019
f82432d
update
peckfly May 5, 2019
9ff41a7
add SpringBoot AutoConfiguration notes
peckfly May 6, 2019
aa5869b
update
peckfly May 6, 2019
f74f048
update
peckfly May 6, 2019
c5b3fdd
update
peckfly May 9, 2019
754b8f1
update
peckfly May 10, 2019
8be4de3
update
peckfly May 10, 2019
fd1b1ca
update
peckfly May 10, 2019
0ab1cb0
update
peckfly May 11, 2019
b00b268
update
peckfly May 11, 2019
04f5393
update
peckfly May 11, 2019
ef9dbac
update
peckfly May 11, 2019
686e05a
update
peckfly May 12, 2019
7671a05
update
peckfly May 12, 2019
11a664f
update
peckfly May 12, 2019
5d9aa36
update
peckfly May 13, 2019
e398f7e
update
peckfly May 13, 2019
d997f2e
update
peckfly May 14, 2019
20ffe1e
update
peckfly May 14, 2019
09fd930
update
peckfly May 14, 2019
aff8088
update
peckfly May 14, 2019
349e541
update
peckfly May 14, 2019
7bba679
update
peckfly May 14, 2019
f73cdc3
update
peckfly May 17, 2019
2804264
update
peckfly May 17, 2019
71a5264
update
peckfly May 17, 2019
1a8fc25
update
peckfly May 18, 2019
4d3cd0e
update
peckfly May 18, 2019
6729898
update
peckfly May 18, 2019
6dfbae6
update
peckfly May 18, 2019
e29082a
update
peckfly May 23, 2019
560fb29
update
peckfly May 26, 2019
16d53bb
update
peckfly May 26, 2019
ab76864
将JVM部分两个简单文档合并到Jvm总结(二)中
peckfly Jun 2, 2019
f4d30f9
更新【类加载部分】
peckfly Jun 2, 2019
3773990
update
peckfly Jun 8, 2019
714a029
modify
peckfly Jul 16, 2019
4044773
修改java8
peckfly Jul 19, 2019
7bae540
d
peckfly Jul 19, 2019
377cfec
d
peckfly Jul 20, 2019
65674aa
修改JVM
peckfly Jul 21, 2019
dd04b4a
change
peckfly Jul 21, 2019
b3f1036
update
peckfly Jul 21, 2019
c7c27cd
update
peckfly Jul 21, 2019
8e49406
update
peckfly Jul 21, 2019
a07868c
update
peckfly Jul 21, 2019
570e011
update
peckfly Jul 22, 2019
b9b377a
update
peckfly Jul 23, 2019
5f83fbf
update
peckfly Jul 26, 2019
1a972dc
update
peckfly Jul 28, 2019
ddc423b
update
peckfly Aug 1, 2019
eb266d4
update
peckfly Aug 2, 2019
a823ff1
update
peckfly Aug 2, 2019
f10aaba
update
Aug 2, 2019
bdc8db5
fixed conflict
Aug 2, 2019
f39cbe2
update
Aug 4, 2019
5ca820c
update
Aug 5, 2019
127b6df
update
Aug 8, 2019
3acfcc3
update
Aug 9, 2019
fb651cf
update
Aug 11, 2019
fd41440
update
peckfly Aug 12, 2019
afd010a
update
Aug 14, 2019
1a5c502
update
peckfly Aug 15, 2019
56a9b0f
update
Aug 15, 2019
1054718
update
peckfly Aug 15, 2019
13659d5
update
peckfly Aug 17, 2019
50ff1ba
update
peckfly Aug 19, 2019
573409b
update
peckfly Aug 20, 2019
996c0e3
update
Aug 20, 2019
ab02cb9
update
Aug 21, 2019
afd9076
update
peckfly Aug 25, 2019
60d9cd6
update
peckfly Aug 25, 2019
c70eb9d
update
peckfly Aug 25, 2019
9e9a14e
update
peckfly Aug 25, 2019
53c37d3
update
peckfly Aug 29, 2019
01241c6
update
peckfly Aug 30, 2019
cb0a741
update
peckfly Sep 1, 2019
2b6cb90
update
peckfly Sep 1, 2019
116d990
update
peckfly Sep 16, 2019
68d62eb
update
peckfly Oct 24, 2019
3ac6a5b
update
peckfly Oct 28, 2019
abc2e2f
update
peckfly Nov 4, 2019
6117654
update
peckfly Nov 4, 2019
85f130f
update
peckfly Nov 11, 2019
2bef932
update
peckfly Nov 11, 2019
51e525c
update
peckfly Nov 11, 2019
f658e64
update
peckfly Nov 11, 2019
0ea47f3
update
peckfly Nov 13, 2019
6685111
update
peckfly Nov 17, 2019
2766c88
update
peckfly Nov 17, 2019
aeb0404
update
peckfly Nov 17, 2019
408cdc7
update
peckfly Dec 6, 2019
7a000e2
update
Dec 16, 2019
15427a1
update
Dec 16, 2019
bb6f252
update
Dec 16, 2019
9581e73
test
zxincool Mar 25, 2020
a7a78f4
Merge pull request #1 from ZXZxin/master
binbinbin5 Jul 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2,897 changes: 2,897 additions & 0 deletions Algorithm/ACM模板(C++).md

Large diffs are not rendered by default.

3,115 changes: 3,115 additions & 0 deletions Algorithm/ACM模板(Java).md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* Codeforces - 1097B. Petr and a Combination Lock(枚举)
***

### <font color = red id = "1">Codeforces - 977F. Consecutive Subsequence( Map + DP)
### Codeforces - 977F. Consecutive Subsequence( Map + DP)
#### [题目链接](https://codeforces.com/problemset/problem/977/F)

> https://codeforces.com/problemset/problem/977/F

#### 题目
**求最长的连续递增子序列(注意是<font color = blue>连续递增</font>(也就是值前后相差为`1`)), 输出长度以及子序列的下标。**
**求最长的连续递增子序列(注意是连续递增(也就是值前后相差为`1`)), 输出长度以及子序列的下标。**

![在这里插入图片描述](images/977F_t.png)
![在这里插入图片描述](images/977F_t2.png)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
## Codeforces - 1133D. Zero Quantity Maximization(哈希)

#### [题目链接](https://codeforces.com/problemset/problem/1133/D)

> https://codeforces.com/problemset/problem/1133/D

#### 题目

就是给你`n`,然后两个数目为`n`个数组`a[]、b[]`,要你随便找一个数`d`(可以是浮点数和整数),使得`d * a[i] + b[i] = 0`的数目数目最多。求出最多的`0`。

![1133D_t.png](images/1133D_t.png)

![1133D_t2.png](images/1133D_t2.png)

### 解析

重点是怎么哈希,这里先求得两个数的最大公约数,然后相除,然后在`map`中的数只要是`a == a2 && b == b2`或者`a == -a2 && b == -b2`的就可以看做同一个。

一开始没有注意`if(a[i] == 0 && b[i] != 0) continue;`,在这里wrong了挺多次。这种情况是不可能为`0`的。

```java
import java.io.*;
import java.util.*;

public class Main {

static PrintStream out = System.out;

static class Pair {
int f, s;

public Pair(int f, int s) {
this.f = f;
this.s = s;
}

@Override
public boolean equals(Object o) {
Pair tr = (Pair) o;
return (f == tr.f && s == tr.s) || (f == -tr.f && s == -tr.s);
}
@Override
public int hashCode() {
return 31 * f + s;
}
}

// 12 16
static int gcd(int a, int b) {
int r = 0;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}

static void solve(InputStream stream) {
Scanner in = new Scanner(new BufferedInputStream(stream));
int n = in.nextInt();
int[] a = new int[n];
int[] b = new int[n];
boolean good = false;
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
if (a[i] != 0) good = true;
}
for (int i = 0; i < n; i++) {
b[i] = in.nextInt();
if (b[i] == 0) good = true;
}
if (!good) {
System.out.println(0);
return;
}
HashMap<Pair, Integer> map = new HashMap<>();
int allZero = 0, fiZero = 0;
for (int i = 0; i < n; i++) {
if(a[i] == 0 && b[i] != 0) continue;//在这里wrong了挺多次
if(a[i] != 0 && b[i] == 0) {
fiZero++;
continue;
}
int d = gcd(a[i], b[i]);
if (d != 0) {
Pair p = new Pair(a[i] / d, b[i] / d);
map.put(p, map.getOrDefault(p, 0) + 1);
} else {
allZero++;
}
}
int res = fiZero; // 有可能是 0 -> X ,就直接取0了
for (Pair key : map.keySet())
res = Math.max(res, map.get(key));
out.println(res + allZero);
}

public static void main(String[] args) {
solve(System.in);
}
}
```



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* [Codeforces - 330B - Road Construction](#codeforces---330b---road-construction)
* [GYM - 101502I - Move Between Numbers](#gym---101502i---move-between-numbers)
***
### <font color = red id = "1">Codeforces - 1082A - Vasya and Book
### Codeforces - 1082A - Vasya and Book
#### [题目链接](http://codeforces.com/problemset/problem/1082/A)

> http://codeforces.com/problemset/problem/1082/A
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
## Codeforces - 1133F1. Spanning Tree with Maximum Degree.md(DFS,记录父亲)

#### [题目链接](https://codeforces.com/problemset/problem/1133/F1)

> https://codeforces.com/problemset/problem/1133/F1

#### 题目

给你一个图,要你求必须包含**度最大的点的所有相连边**的生成树。

![1133F1_t.png](images/1133F1_t.png)

![1133F1_t2.png](images/1133F1_t2.png)

![1133F1_t3.png](images/1133F1_t3.png)

![1133F1_t4.png](images/1133F1_t4.png)

![1133F1_t5.png](images/1133F1_t5.png)

#### 解析

思路:

* 先找出度最大的度的顶点`maxv`。然后先将这个点的邻接边加入结果。
* 然后从和`maxv`邻接的点开始`dfs`,这个过程既要记录`vis`是否访问,又要记录一个父亲节点,这样才比较好维护;

![1133F1_s.png](images/1133F1_s.png)

代码:

```java
import java.io.*;
import java.util.*;

public class Main {

static PrintStream out = System.out;

static boolean[] vis;
static ArrayList<Integer> G[];

static void solve(InputStream stream) {
Scanner in = new Scanner(new BufferedInputStream(stream));
int n = in.nextInt();
int m = in.nextInt();
G = new ArrayList[n + 1];
int[] deg = new int[n + 1];
for (int i = 1; i <= n; i++) G[i] = new ArrayList<>();
for (int i = 0; i < m; i++) {
int from = in.nextInt();
int to = in.nextInt();
deg[to]++;
deg[from]++;
G[from].add(to);
G[to].add(from);
}
int maxDeg = 0;
int maxv = 0;
for (int i = 1; i <= n; i++) { // 找度最大的
if (deg[i] > maxDeg) {
maxDeg = deg[i];
maxv = i;
}
}
vis = new boolean[n + 1];
vis[maxv] = true;
for(int to : G[maxv]){ // 先将度最大的相连的边连接起来
vis[to] = true;
out.println(maxv + " " + to);
}
for(int to : G[maxv]) dfs(to, maxv);
}

static void dfs(int cur, int par) { // 记录当前节点和父亲节点
// if(vis[cur]) return ; // 不要写这里,不然第一次就不能进去
vis[cur] = true;
for (int to : G[cur]) {
if(to == par || vis[to]) continue;
out.println(cur + " " + to);
dfs(to, cur);
}
}

public static void main(String[] args) {
solve(System.in);
}
}
```

Binary file added Algorithm/Codeforces/Graph/images/1133F1_s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Algorithm/Codeforces/Graph/images/1133F1_t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Algorithm/Codeforces/Graph/images/1133F1_t2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Algorithm/Codeforces/Graph/images/1133F1_t4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Algorithm/Codeforces/Graph/images/1133F1_t5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions Algorithm/Codeforces/Greedy/Codeforces - 1130B. Two Cakes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## Codeforces - 1130B. Two Cakes

#### [题目链接](https://codeforces.com/problemset/problem/1130/B)

> https://codeforces.com/problemset/problem/1130/B

#### 题目

给你`n`和`2n`个数。(`1~n`之间的数各两个)

两个人都同时从最左边的`1`位置开始出发,每次依次去找`1, 2, 3, ..., n`。问你两个人需要走的最小的路程。

![1130_B_t.png](images/1130_B_t.png)

![1130_B_t2.png](images/1130_B_t2.png)

### 解析

贪心的策略就是:

当前的`abs(id1 - p1[i + 1]) + abs(id2 - p2[i + 1]) `和`abs(id1 - p2[i + 1]) + abs(id2 - p1[i + 1])`哪个更小,就去哪个。

```java
import java.io.*;
import java.util.*;

public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintStream out = System.out;
int n = in.nextInt();
int[] arr = new int[n * 2 + 1];
int[] p1 = new int[n * 2 + 1];
int[] p2 = new int[n * 2 + 1];
for (int i = 1; i <= 2 * n; i++) {
arr[i] = in.nextInt();
if (p1[arr[i]] == 0)
p1[arr[i]] = i;
else
p2[arr[i]] = i;
}

// System.out.println(Arrays.toString(p1));
// System.out.println(Arrays.toString(p2));

int id1 = 1, id2 = 1;
long r1 = 0, r2 = 0;
for (int i = 0; i < n; i++) { // 每一个数
if (abs(id1 - p1[i + 1]) + abs(id2 - p2[i + 1]) <
abs(id1 - p2[i + 1]) + abs(id2 - p1[i + 1])) { //贪心策略
r1 += abs(p1[i + 1] - id1);
id1 = p1[i + 1];
r2 += abs(p2[i + 1] - id2);
id2 = p2[i + 1];
} else {
r1 += abs(p2[i + 1] - id1);
id1 = p2[i + 1];
r2 += abs(p1[i + 1] - id2);
id2 = p1[i + 1];
}
}
out.println(r1 + r2);
}

static int abs(int n) {
return Math.abs(n);
}
}

```

48 changes: 48 additions & 0 deletions Algorithm/Codeforces/Greedy/Codeforces - 1157B. Long Number.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Codeforces - 1157B. Long Number

#### [题目链接](https://codeforces.com/problemset/problem/1157/B)

> https://codeforces.com/problemset/problem/1157/B

#### 题目

![1556624729268](assets/1556624729268.png)

### 解析

模拟即可。注意情况`if(f[s[i] - '0'] == s[i] - '0') continue`。

```java
import java.util.*;
import java.io.*;

public class Main{

static void solve(Scanner in, PrintWriter out){
int n = in.nextInt();
char[] s = in.next().toCharArray();
int[] f = new int[10];
for(int i = 1; i < 10; i++) f[i] = in.nextInt();
boolean flag = true;
for(int i = 0; i < n; i++){
if(f[s[i] - '0'] > s[i] - '0'){
s[i] = (char)(f[s[i] - '0'] + '0');
flag = false;
}else {
if(f[s[i] - '0'] == s[i] - '0') continue; // 注意这里
if(!flag) break;
}
}
out.println(s);
}

public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintWriter out = new PrintWriter(System.out);
solve(in, out);
out.close();
}
}

```

Loading