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
Open sidebar
张敏捷
SRQuestions
Commits
f0714c0f
Commit
f0714c0f
authored
Oct 29, 2019
by
majexh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
uncomplete second
parent
7eb7ce2c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
8 deletions
+37
-8
misc.xml
.idea/misc.xml
+2
-1
Second.java
度小满/second/Second.java
+35
-7
No files found.
.idea/misc.xml
View file @
f0714c0f
...
...
@@ -3,7 +3,7 @@
<component
name=
"JavaScriptSettings"
>
<option
name=
"languageLevel"
value=
"ES6"
/>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_11"
default=
"false"
project-jdk-name=
"11"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_11"
default=
"false"
project-jdk-name=
"11
.0.4
"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/out"
/>
</component>
</project>
\ No newline at end of file
度小满/second/Second.java
View file @
f0714c0f
packa
ge
second
;
packa
ge
second
;
package
second
;
import
javafx.util.Pair
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Scanner
;
public
class
Second
{
public
void
swap
(
List
<
Pair
<
Integer
,
Integer
>>
list
,
int
child
,
int
father
)
{
Integer
timeTemp
=
list
.
get
(
child
).
getKey
(),
weightTemp
=
list
.
get
(
child
).
getValue
();
list
.
set
(
child
,
new
Pair
<>(
list
.
get
(
father
).
getKey
(),
list
.
get
(
father
).
getValue
()));
list
.
set
(
father
,
new
Pair
<>(
timeTemp
,
weightTemp
));
}
public
void
add
(
List
<
Pair
<
Integer
,
Integer
>>
list
,
int
time
,
int
weight
)
{
list
.
add
(
new
Pair
<>(
time
,
weight
));
// list 已经是一个小顶堆 重新排序
for
(
int
i
=
list
.
size
()
-
1
;
i
>=
0
;)
{
// 父节点的序号
int
father
=
i
%
2
==
0
?
(
i
-
2
)
/
2
:
i
/
2
;
// 与父节点比较
if
(
list
.
get
(
i
).
getKey
()
<
list
.
get
(
father
).
getKey
())
{
swap
(
list
,
i
,
father
);
}
else
{
break
;
}
i
=
father
;
}
}
/**
* 弹出值 并且在弹出之后 重新从上向下构建 小顶堆
*/
public
void
pop
()
{
}
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -18,19 +48,17 @@ public class Second {
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
weights
[
i
]
=
scanner
.
nextInt
();
}
List
<
Integer
>
heap
=
new
LinkedList
<>();
Second
second
=
new
Second
();
List
<
Pair
<
Integer
,
Integer
>>
heap
=
new
LinkedList
<>();
// 用堆排序的话就需要在出去的时候
int
currentTime
=
0
,
currentWeight
=
w
,
index
=
0
;
while
(
true
)
{
while
(
currentWeight
>=
0
)
{
if
(
index
>=
n
)
break
;
// 入堆
heap
.
add
(
currentTime
+
t
[
index
]);
// 入堆
并调整
second
.
add
(
heap
,
currentTime
+
t
[
index
],
weights
[
index
]);
currentWeight
-=
weights
[
index
];
index
++;
// TODO: 调整堆成为最小堆
}
// 出堆 直到下一个车能够入堆为止
// while () {
...
...
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