Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_36480062
Algorithm
提交
c304bf85
A
Algorithm
项目概览
qq_36480062
/
Algorithm
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
Algorithm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c304bf85
编写于
12月 21, 2019
作者:
qq_36480062
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commit
上级
30eb9dfb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
34 deletion
+31
-34
algorithm/UnionFind/修计算机.java
algorithm/UnionFind/修计算机.java
+3
-29
algorithm/com/shiyu/tsdt.java
algorithm/com/shiyu/tsdt.java
+9
-0
algorithm/greedy/做作业.java
algorithm/greedy/做作业.java
+2
-0
algorithm/greedy/卖商品.java
algorithm/greedy/卖商品.java
+17
-5
未找到文件。
algorithm/UnionFind/修计算机.java
浏览文件 @
c304bf85
...
...
@@ -52,7 +52,7 @@ public class 修计算机 {
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
n
=
sc
.
nextInt
();
//计算机数量
int
d
=
sc
.
nextInt
();
//可通信距离
UnionFind
E
u
=
new
UnionFindE
(
n
);
UnionFind
u
=
new
UnionFind
(
n
);
dx
=
new
int
[
n
];
dy
=
new
int
[
n
];
ArrayList
<
Integer
>
list
=
new
ArrayList
<>();
//已经修好的计算机
...
...
@@ -88,31 +88,4 @@ public class 修计算机 {
public
static
double
dis
(
int
a
,
int
b
)
{
return
Math
.
sqrt
(
Math
.
abs
((
dx
[
a
]
-
dx
[
b
]))
*
Math
.
abs
((
dx
[
a
]
-
dx
[
b
]))
+
Math
.
abs
((
dy
[
a
]
-
dy
[
b
]))
*
Math
.
abs
((
dy
[
a
]
-
dy
[
b
])));
}
}
class
UnionFindE
{
private
int
[]
parent
;
UnionFindE
(
int
n
)
{
parent
=
new
int
[
n
+
1
];
for
(
int
i
=
0
;
i
<
n
+
1
;
i
++)
{
parent
[
i
]
=
i
;
}
}
public
void
Union
(
int
p
,
int
q
)
{
int
pRoot
=
find
(
p
);
int
qRoot
=
find
(
q
);
if
(
pRoot
!=
qRoot
)
{
parent
[
pRoot
]
=
qRoot
;
}
}
public
int
find
(
int
p
)
{
while
(
p
!=
parent
[
p
])
{
p
=
find
(
parent
[
p
]);
}
return
parent
[
p
];
}
}
}
\ No newline at end of file
algorithm/com/shiyu/tsdt.java
0 → 100644
浏览文件 @
c304bf85
package
com.shiyu
;
public
class
tsdt
{
public
static
void
main
(
String
[]
args
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
System
.
out
.
println
(
i
);
}
}
}
algorithm/greedy/做作业.java
浏览文件 @
c304bf85
...
...
@@ -61,7 +61,9 @@ public class 做作业 {
public
static
void
main
(
String
[]
args
)
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
s
=
sc
.
nextInt
();
for
(
int
i
=
0
;
i
<
s
;
i
++)
{
}
}
}
//#include<stdio.h>
...
...
algorithm/greedy/卖商品.java
浏览文件 @
c304bf85
...
...
@@ -14,7 +14,7 @@ import java.util.Scanner;
*/
public
class
卖商品
{
static
class
Node
{
int
profit
;
int
profit
;
//价值
int
deadline
;
public
int
getProfit
()
{
...
...
@@ -56,12 +56,24 @@ public class 卖商品 {
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
list
.
add
(
new
Node
(
sc
.
nextInt
(),
sc
.
nextInt
()));
}
list
.
sort
((
o1
,
o2
)
->
o2
.
profit
-
o1
.
profit
);
boolean
[]
visit
=
new
boolean
[
count
];
System
.
out
.
println
(
list
)
;
list
.
add
(
0
,
new
Node
(
1
,
1
)
);
list
.
sort
((
o1
,
o2
)
->
o2
.
profit
-
o1
.
profit
);
//按照商品价格从大到小排列
boolean
[]
visit
=
new
boolean
[
1000
]
;
for
(
int
i
=
1
;
i
<=
count
;
i
++)
{
if
(!
visit
[
list
.
get
(
i
).
deadline
])
{
//如果这一天没有被占用
maxProfit
+=
list
.
get
(
i
).
profit
;
//要了这一天
visit
[
list
.
get
(
i
).
deadline
]
=
true
;
//占用这一天
}
else
{
for
(
int
j
=
list
.
get
(
i
).
deadline
-
1
;
j
>=
1
;
j
--)
{
if
(!
visit
[
j
])
{
maxProfit
+=
list
.
get
(
i
).
profit
;
visit
[
j
]
=
true
;
break
;
}
}
}
}
System
.
out
.
println
(
maxProfit
);
}
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录