Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SRQuestions
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
文档服务地址:
http://47.92.0.57:3000/
周报索引地址:
http://47.92.0.57:3000/s/NruNXRYmV
Open sidebar
张敏捷
SRQuestions
Commits
b1619211
Commit
b1619211
authored
Apr 13, 2020
by
张敏捷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add 2020 阿里
parent
329c989c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
0 deletions
+131
-0
First.java
2020阿里/First.java
+67
-0
Second.java
2020阿里/Second.java
+64
-0
No files found.
2020阿里/First.java
0 → 100644
View file @
b1619211
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Scanner
;
public
class
First
{
public
static
int
dfs
(
HashMap
<
Integer
,
List
<
Integer
>>
map
,
int
start
,
boolean
[]
memo
)
{
List
<
Integer
>
temp
=
map
.
get
(
start
);
memo
[
start
]
=
true
;
int
res
=
temp
.
size
();
for
(
Integer
admire
:
temp
)
{
if
(
start
<
admire
&&
!
memo
[
admire
])
res
+=
dfs
(
map
,
admire
,
memo
);
}
memo
[
start
]
=
false
;
return
res
;
}
/**
* 这道题的意思是 给定一个数组 这个数组里面的元素是从1开始的
* 这个数组满足一个规则 其下标越小 那么这个数组的这个元素的能力越大
* 当只有这个元素的能力比另一个元素大的时候 这个元素才能够被后面的元素投票
* 问题:
* 给定一个数组 这个数组里面的元素表示
* 当前这个下标的人可以自己投票 或者给自己的下标所指的
* 人投票的人投票
* 如果这个元素是0 那么他只能给自己投票
* 针对这个数组的每一个下标 输出他能够被投票的最大值
* 例如
* 输入
* 4
* 0 1 1 1
* 输出
* 4 (后面三位都都仰慕1号位的人 因此都投给他投的人 也就是自己)
* 1
* 1
* 1
*/
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
int
n
=
scanner
.
nextInt
();
int
[]
admires
=
new
int
[
n
+
1
];
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
admires
[
i
]
=
scanner
.
nextInt
();
}
HashMap
<
Integer
,
List
<
Integer
>>
map
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<
admires
.
length
;
i
++)
{
if
(!
map
.
containsKey
(
i
))
{
map
.
put
(
i
,
new
ArrayList
<>());
}
if
(
admires
[
i
]
!=
0
&&
admires
[
i
]
!=
i
)
{
if
(!
map
.
containsKey
(
admires
[
i
]))
{
map
.
put
(
admires
[
i
],
new
ArrayList
<>());
}
List
<
Integer
>
temp
=
map
.
get
(
admires
[
i
]);
temp
.
add
(
i
);
}
}
System
.
out
.
println
(
map
);
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
System
.
out
.
println
(
dfs
(
map
,
i
,
new
boolean
[
n
+
1
])
+
1
);
}
}
}
2020阿里/Second.java
0 → 100644
View file @
b1619211
package
com
.
company
;
package
com
.
company
;
import
java.util.*
;
public
class
Second
{
static
class
Pair
{
public
Integer
key
;
public
Integer
value
;
public
Pair
(
Integer
key
,
Integer
value
)
{
this
.
key
=
key
;
this
.
value
=
value
;
}
}
public
static
int
resolve
(
HashMap
<
Integer
,
List
<
Pair
>>
map
,
int
start
,
int
end
,
int
size
)
{
boolean
[]
memo
=
new
boolean
[
size
];
return
dfs
(
map
,
start
,
end
,
memo
,
0
);
}
public
static
int
dfs
(
HashMap
<
Integer
,
List
<
Pair
>>
map
,
int
start
,
int
end
,
boolean
[]
memo
,
int
current
)
{
if
(
start
==
end
)
return
current
;
memo
[
start
]
=
true
;
List
<
Pair
>
temp
=
map
.
get
(
start
);
int
res
=
Integer
.
MAX_VALUE
;
for
(
Pair
tempPair
:
temp
)
{
if
(!
memo
[
tempPair
.
key
])
{
res
=
Math
.
min
(
res
,
dfs
(
map
,
tempPair
.
key
,
end
,
memo
,
current
+
tempPair
.
value
));
}
}
memo
[
start
]
=
false
;
return
res
;
}
/**
* 这道题是说
* 给定 n 个城市(下标从1开始)和 m 条城市间的路径 以及一个目标城市 x (n种的下标)
* 接下来输入 m 行 表示 这个 m 条路径的 起始点 a 终止点 b 和 路程消费的时间 l
* 为 每个城市中都有一个人 需要到目标城市 x
* 而且每个人都会选择最短的路径
* 那么 这 n 个人选择的路径中 路径消费最长时间的是多少
*/
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
int
n
=
scanner
.
nextInt
(),
m
=
scanner
.
nextInt
(),
x
=
scanner
.
nextInt
();
HashMap
<
Integer
,
List
<
Pair
>>
map
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
m
;
i
++)
{
int
a
=
scanner
.
nextInt
(),
b
=
scanner
.
nextInt
(),
l
=
scanner
.
nextInt
();
if
(!
map
.
containsKey
(
a
))
{
map
.
put
(
a
,
new
ArrayList
<>());
}
List
<
Pair
>
temp
=
map
.
get
(
a
);
temp
.
add
(
new
Pair
(
b
,
l
));
}
int
res
=
Integer
.
MIN_VALUE
;
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
res
=
Math
.
max
(
res
,
resolve
(
map
,
i
,
x
,
n
+
1
)
+
resolve
(
map
,
x
,
i
,
n
+
1
));
}
System
.
out
.
println
(
res
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment