Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
禅与计算机程序设计艺术
contest_exercises_template
提交
6f8f145f
C
contest_exercises_template
项目概览
禅与计算机程序设计艺术
/
contest_exercises_template
该项目与 Fork 源项目分叉
Fork自
CSDN 技术社区 / contest_exercises_template
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
contest_exercises_template
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6f8f145f
编写于
6月 29, 2023
作者:
C
chenguangjian.jk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test pass
上级
b76757e1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
127 addition
and
16 deletion
+127
-16
exercises/chenguangjian/中等/机器猫/solution.java
exercises/chenguangjian/中等/机器猫/solution.java
+52
-9
exercises/chenguangjian/中等/覆盖面积/solution.java
exercises/chenguangjian/中等/覆盖面积/solution.java
+31
-4
exercises/chenguangjian/困难/求解秩矩阵/solution.java
exercises/chenguangjian/困难/求解秩矩阵/solution.java
+44
-3
未找到文件。
exercises/chenguangjian/中等/机器猫/solution.java
浏览文件 @
6f8f145f
class
Solution
{
public
boolean
robot
(
String
command
,
int
[][]
barriers
,
int
x
,
int
y
)
{
System
.
out
.
println
();
System
.
out
.
println
(
command
);
System
.
out
.
println
(
Arrays
.
deepToString
(
barriers
));
System
.
out
.
println
(
x
);
System
.
out
.
println
(
y
);
import
java.util.Scanner
;
import
java.util.*
;
class
Main
{
public
static
void
main
(
String
[]
args
)
{
// 控制台输入
Scanner
scanner
=
new
Scanner
(
System
.
in
);
String
command
=
scanner
.
nextLine
();
String
barriersStr
=
scanner
.
nextLine
();
int
[][]
barriers
=
new
int
[][]{};
// 解析字符串,构造二维数组
barriersStr
=
barriersStr
.
replaceAll
(
" "
,
""
);
if
(!
"[]"
.
equals
(
barriersStr
)){
String
[]
strArr
=
barriersStr
.
replaceAll
(
"\\[\\["
,
""
).
replaceAll
(
"\\]\\]"
,
""
).
split
(
"\\],\\["
);
barriers
=
new
int
[
strArr
.
length
][];
for
(
int
i
=
0
;
i
<
strArr
.
length
;
i
++)
{
String
[]
innerArr
=
strArr
[
i
].
split
(
","
);
barriers
[
i
]
=
new
int
[
innerArr
.
length
];
for
(
int
j
=
0
;
j
<
innerArr
.
length
;
j
++)
{
barriers
[
i
][
j
]
=
Integer
.
parseInt
(
innerArr
[
j
].
trim
());
}
}
}
int
x
=
scanner
.
nextInt
();
int
y
=
scanner
.
nextInt
();
scanner
.
close
();
// 调用方法
boolean
result
=
robot
(
command
,
barriers
,
x
,
y
);
// 输出结果
System
.
out
.
println
(
result
);
}
public
static
boolean
robot
(
String
command
,
int
[][]
barriers
,
int
x
,
int
y
)
{
int
dx
=
0
,
dy
=
0
;
char
[]
cmd
=
command
.
toCharArray
();
// 把String转为数组,方便遍历。
...
...
@@ -36,7 +76,7 @@ class Solution {
}
// 判断是否经过该点,经过返回走的次数,没经过返回-1。
public
int
isPassed
(
char
[]
cmd
,
int
x
,
int
y
,
int
dx
,
int
dy
)
{
public
static
int
isPassed
(
char
[]
cmd
,
int
x
,
int
y
,
int
dx
,
int
dy
)
{
int
round
=
Math
.
min
(
x
/
dx
,
y
/
dy
);
// 计算走到第x-1或y-1层需要多少轮
int
cnt
=
cmd
.
length
*
round
;
// 前几轮的总次数
dx
*=
round
;
...
...
@@ -59,4 +99,6 @@ class Solution {
return
-
1
;
}
}
}
\ No newline at end of file
exercises/chenguangjian/中等/覆盖面积/solution.java
浏览文件 @
6f8f145f
class
Solution
{
public
int
computeArea
(
int
ax1
,
int
ay1
,
int
ax2
,
int
ay2
,
int
bx1
,
int
by1
,
int
bx2
,
int
by2
)
{
import
java.util.Scanner
;
class
Main
{
public
static
void
main
(
String
[]
args
)
{
Scanner
scan
=
new
Scanner
(
System
.
in
);
int
ax1
=
Integer
.
parseInt
(
scan
.
nextLine
().
trim
());
int
ay1
=
Integer
.
parseInt
(
scan
.
nextLine
().
trim
());
int
ax2
=
Integer
.
parseInt
(
scan
.
nextLine
().
trim
());
int
ay2
=
Integer
.
parseInt
(
scan
.
nextLine
().
trim
());
int
bx1
=
Integer
.
parseInt
(
scan
.
nextLine
().
trim
());
int
by1
=
Integer
.
parseInt
(
scan
.
nextLine
().
trim
());
int
bx2
=
Integer
.
parseInt
(
scan
.
nextLine
().
trim
());
int
by2
=
Integer
.
parseInt
(
scan
.
nextLine
().
trim
());
scan
.
close
();
int
result
=
solution
(
ax1
,
ay1
,
ax2
,
ay2
,
bx1
,
by1
,
bx2
,
by2
);
System
.
out
.
println
(
result
);
}
public
static
int
solution
(
int
ax1
,
int
ay1
,
int
ax2
,
int
ay2
,
int
bx1
,
int
by1
,
int
bx2
,
int
by2
)
{
int
area1
=
(
ax2
-
ax1
)
*
(
ay2
-
ay1
),
area2
=
(
bx2
-
bx1
)
*
(
by2
-
by1
);
int
overlapWidth
=
Math
.
min
(
ax2
,
bx2
)
-
Math
.
max
(
ax1
,
bx1
),
overlapHeight
=
Math
.
min
(
ay2
,
by2
)
-
Math
.
max
(
ay1
,
by1
);
int
overlapArea
=
Math
.
max
(
overlapWidth
,
0
)
*
Math
.
max
(
overlapHeight
,
0
);
return
area1
+
area2
-
overlapArea
;
}
}
\ No newline at end of file
}
exercises/chenguangjian/困难/求解秩矩阵/solution.java
浏览文件 @
6f8f145f
class
Solution
{
public
int
[][]
matrixRankTransform
(
int
[][]
matrix
)
{
import
java.util.Scanner
;
import
java.util.*
;
import
java.util.Arrays
;
class
Main
{
public
static
void
main
(
String
[]
args
)
{
// 控制台输入
Scanner
scanner
=
new
Scanner
(
System
.
in
);
String
matrixStr
=
scanner
.
nextLine
();
int
[][]
matrix
=
new
int
[][]{};
// 解析字符串,构造二维数组
matrixStr
=
matrixStr
.
replaceAll
(
" "
,
""
);
if
(!
"[]"
.
equals
(
matrixStr
)){
String
[]
strArr
=
matrixStr
.
replaceAll
(
"\\[\\["
,
""
).
replaceAll
(
"\\]\\]"
,
""
).
split
(
"\\],\\["
);
matrix
=
new
int
[
strArr
.
length
][];
for
(
int
i
=
0
;
i
<
strArr
.
length
;
i
++)
{
String
[]
innerArr
=
strArr
[
i
].
split
(
","
);
matrix
[
i
]
=
new
int
[
innerArr
.
length
];
for
(
int
j
=
0
;
j
<
innerArr
.
length
;
j
++)
{
matrix
[
i
][
j
]
=
Integer
.
parseInt
(
innerArr
[
j
].
trim
());
}
}
}
scanner
.
close
();
// 调用方法
int
[][]
res
=
matrixRankTransform
(
matrix
);
// 输出结果
System
.
out
.
println
(
Arrays
.
deepToString
(
res
));
}
public
static
int
[][]
matrixRankTransform
(
int
[][]
matrix
)
{
int
m
=
matrix
.
length
,
n
=
matrix
[
0
].
length
;
UnionFind
uf
=
new
UnionFind
(
m
,
n
);
for
(
int
i
=
0
;
i
<
m
;
i
++)
{
...
...
@@ -119,8 +158,10 @@ class Solution {
}
return
res
;
}
}
}
class
UnionFind
{
int
m
,
n
;
int
[][][]
root
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录