Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_36480062
Algorithm
提交
5e322493
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 搜索 >>
提交
5e322493
编写于
2月 24, 2020
作者:
qq_36480062
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commit
上级
2f99266f
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
200 addition
and
62 deletion
+200
-62
OJ题解/src/大整数运算技巧/HDOJ阶乘2940.java
OJ题解/src/大整数运算技巧/HDOJ阶乘2940.java
+0
-1
algorithm/UnionFind/UnionFind.java
algorithm/UnionFind/UnionFind.java
+4
-3
algorithm/Water/最大最小公倍数.java
algorithm/Water/最大最小公倍数.java
+7
-0
algorithm/Water/杨辉三角形.java
algorithm/Water/杨辉三角形.java
+67
-0
algorithm/Water/阶乘.java
algorithm/Water/阶乘.java
+25
-0
algorithm/com/shiyu/Main.java
algorithm/com/shiyu/Main.java
+4
-52
algorithm/com/shiyu/tsdt.java
algorithm/com/shiyu/tsdt.java
+4
-0
algorithm/com/shiyu/开灯.java
algorithm/com/shiyu/开灯.java
+2
-1
algorithm/string/KMP.java
algorithm/string/KMP.java
+47
-2
algorithm/wei/zhuanhuan.java
algorithm/wei/zhuanhuan.java
+0
-2
algorithm/进制转换/进制转换.java
algorithm/进制转换/进制转换.java
+40
-1
未找到文件。
OJ题解/src/大整数运算技巧/HDOJ阶乘2940.java
浏览文件 @
5e322493
...
...
@@ -42,5 +42,4 @@ public class HDOJ阶乘2940 {
}
}
}
}
algorithm/UnionFind/UnionFind.java
浏览文件 @
5e322493
package
UnionFind
;
//最优实现并查集
public
class
UnionFind
{
public
int
[]
parent
;
private
int
[]
rank
;
UnionFind
(
int
n
)
{
parent
=
new
int
[
n
+
1
];
rank
=
new
int
[
n
+
1
];
for
(
int
i
=
0
;
i
<
n
+
1
;
i
++)
{
parent
=
new
int
[
n
+
1
];
rank
=
new
int
[
n
+
1
];
for
(
int
i
=
0
;
i
<
n
+
1
;
i
++)
{
parent
[
i
]
=
i
;
rank
[
i
]
=
1
;
}
...
...
algorithm/Water/最大最小公倍数.java
0 → 100644
浏览文件 @
5e322493
package
Water
;
public
class
最大最小公倍数
{
public
static
void
main
(
String
[]
args
)
{
}
}
algorithm/Water/杨辉三角形.java
0 → 100644
浏览文件 @
5e322493
package
Water
;
import
java.util.Scanner
;
/**
* http://lx.lanqiao.cn/problem.page?gpid=T10
* 问题描述
* 杨辉三角形又称Pascal三角形,它的第i+1行是(a+b)i的展开式的系数。
*
*
* 它的一个重要性质是:三角形中的每个数字等于它两肩上的数字相加。
*
*
* 下面给出了杨辉三角形的前4行:
*
*
* 1
*
*
* 1 1
*
*
* 1 2 1
*
*
* 1 3 3 1
*
*
* 给出n,输出它的前n行。
*
* 输入格式
* 输入包含一个数n。
*
* 输出格式
* 输出杨辉三角形的前n行。每一行从这一行的第一个数开始依次输出,中间使用一个空格分隔。请不要在前面输出多余的空格。
* 样例输入
* 4
* 样例输出
* 1
* 1 1
* 1 2 1
* 1 3 3 1
* 数据规模与约定
* 1 <= n <= 34。
*/
public
class
杨辉三角形
{
public
static
void
main
(
String
[]
args
)
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
n
=
sc
.
nextInt
();
int
[][]
dp
=
new
int
[
n
][
n
];
dp
[
0
][
0
]
=
1
;
for
(
int
i
=
1
;
i
<
n
;
i
++)
{
for
(
int
j
=
0
;
j
<
i
+
1
;
j
++)
{
if
(
j
-
1
>=
0
)
dp
[
i
][
j
]
=
dp
[
i
-
1
][
j
-
1
]
+
dp
[
i
-
1
][
j
];
else
dp
[
i
][
j
]
=
dp
[
i
-
1
][
j
];
}
}
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
for
(
int
j
=
0
;
j
<
i
+
1
;
j
++)
{
System
.
out
.
print
(
dp
[
i
][
j
]
+
" "
);
}
System
.
out
.
println
();
}
}
}
algorithm/Water/阶乘.java
0 → 100644
浏览文件 @
5e322493
package
Water
;
import
java.math.BigInteger
;
import
java.util.Scanner
;
public
class
阶乘
{
public
static
void
main
(
String
[]
args
)
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
nextInt
=
sc
.
nextInt
();
BigInteger
b
=
BigInteger
.
ONE
;
for
(
long
i
=
1
;
i
<=
nextInt
;
i
++)
{
b
=
b
.
multiply
(
BigInteger
.
valueOf
(
i
));
}
System
.
out
.
println
(
s
(
b
.
toString
()));
}
public
static
char
s
(
String
n
)
{
for
(
int
i
=
n
.
length
()
-
1
;
i
>=
0
;
i
--)
{
if
(
n
.
charAt
(
i
)
!=
'0'
)
return
n
.
charAt
(
i
);
}
return
0
;
}
}
algorithm/com/shiyu/Main.java
浏览文件 @
5e322493
package
com.shiyu
;
import
java.util.
*
;
import
java.util.
Scanner
;
public
class
Main
{
private
static
class
Node
implements
Comparable
<
Node
>
{
public
int
Juli
;
public
int
You
=
0
;
public
Node
(
int
juli
)
{
Juli
=
juli
;
}
@Override
public
int
compareTo
(
Node
node
)
{
return
this
.
Juli
-
node
.
Juli
;
}
}
public
static
void
main
(
String
[]
args
)
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
N
=
sc
.
nextInt
();
//几个加油站
Node
[]
node
=
new
Node
[
N
+
1
];
for
(
int
i
=
0
;
i
<
N
;
i
++)
{
node
[
i
]
=
new
Node
(
sc
.
nextInt
());
node
[
i
].
You
=
sc
.
nextInt
();
}
int
L
=
sc
.
nextInt
();
int
P
=
sc
.
nextInt
();
for
(
int
i
=
0
;
i
<
N
;
i
++)
{
node
[
i
].
Juli
=
L
-
node
[
i
].
Juli
;
//更改为加油站距离起点的位置
}
node
[
N
]
=
new
Node
(
L
);
Arrays
.
sort
(
node
);
PriorityQueue
<
Integer
>
pq
=
new
PriorityQueue
<
Integer
>(
N
+
10
,
new
Comparator
<
Integer
>()
{
@Override
public
int
compare
(
Integer
t1
,
Integer
t2
)
{
return
t2
-
t1
;
}
});
int
res
=
0
;
//加油次数
int
pos
=
0
;
//当前所在位置
int
tank
=
P
;
//油箱剩的油的数量
for
(
int
i
=
0
;
i
<=
N
;
i
++)
{
//把终点看做加油站,看能不能到这个加油站
int
d
=
node
[
i
].
Juli
-
pos
;
//卡车的位置从0开始,到达第i个加油站需要多少油
while
(
tank
-
d
<
0
)
{
//如果无法到达第i个加油站
if
(
pq
.
size
()
==
0
)
//从优先队列里面没有加油站,没有刻
System
.
out
.
println
(
"-1"
);
tank
+=
pq
.
poll
();
res
++;
}
tank
-=
d
;
//减去走到第i个加油站需要的油,区间是什么呢,
// 第一次区间(0,A[i])需要这么多油,第二次及以后区间(A[i-1],A[i])
// 每次都要维护油的数量,区间消耗的油
pos
=
node
[
i
].
Juli
;
//卡车开到第i个加油站
pq
.
offer
(
node
[
i
].
You
);
//每到一个加油站,就把能加的油加进优先队列
}
System
.
out
.
println
(
res
);
String
next
=
sc
.
next
();
System
.
out
.
println
(
next
.
toLowerCase
());
}
}
}
\ No newline at end of file
algorithm/com/shiyu/tsdt.java
浏览文件 @
5e322493
...
...
@@ -2,6 +2,10 @@ package com.shiyu;
public
class
tsdt
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
153
);
System
.
out
.
println
(
370
);
System
.
out
.
println
(
371
);
System
.
out
.
println
(
407
);
}
...
...
algorithm/com/shiyu/开灯.java
浏览文件 @
5e322493
...
...
@@ -31,4 +31,4 @@ public class 开灯 {
System
.
out
.
print
(
i
+
" "
);
}
}
}
}
\ No newline at end of file
algorithm/string/KMP.java
浏览文件 @
5e322493
package
string
;
import
java.util.Arrays
;
import
java.util.Random
;
/**
* KMP字符串匹配...未完
*/
public
class
KMP
{
public
static
void
main
(
String
[]
args
)
{
for
(
int
i
=
3
;
i
<
1000
;
i
++)
{
String
st
=
randomStr
(
i
);
if
(!
Arrays
.
equals
(
next
(
st
),
nextt
(
st
)))
{
System
.
out
.
println
(
st
);
System
.
out
.
println
(
Arrays
.
toString
(
next
(
st
)));
System
.
out
.
println
(
Arrays
.
toString
(
nextt
(
st
)));
}
}
System
.
out
.
println
(
Arrays
.
toString
(
next
(
"abaabcac"
)));
System
.
out
.
println
(
Arrays
.
toString
(
nextt
(
"abaabcac"
)));
}
public
static
String
randomStr
(
int
len
)
{
StringBuilder
s
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
Random
r
=
new
Random
();
char
random
=
(
char
)
(
r
.
nextInt
(
26
)
+
'a'
);
s
.
append
(
random
);
}
return
s
.
toString
();
}
...
...
@@ -29,6 +53,13 @@ public class KMP {
return
-
1
;
}
/**
* 前缀 指除了最后一个字符以外,一个字符串的全部头部组合;
* 后缀 指除了第一个字符以外,一个字符串的全部尾部组合。
*
* @param ps 模式串
* @return 求解next数组
*/
public
static
int
[]
next
(
String
ps
)
{
int
pLength
=
ps
.
length
();
int
[]
next
=
new
int
[
pLength
];
...
...
@@ -38,6 +69,7 @@ public class KMP {
return
next
;
}
next
[
1
]
=
0
;
int
j
=
1
;
int
k
=
next
[
j
];
//看看j的最长匹配前缀在哪里
while
(
j
<
pLength
-
1
)
{
...
...
@@ -48,8 +80,21 @@ public class KMP {
return
next
;
}
public
static
void
m
()
{
public
static
int
[]
nextt
(
String
ps
)
{
int
pLength
=
ps
.
length
();
int
[]
next
=
new
int
[
pLength
];
char
[]
p
=
ps
.
toCharArray
();
next
[
0
]
=
-
1
;
if
(
ps
.
length
()
==
1
)
{
return
next
;
}
int
j
=
0
,
k
=
-
1
;
while
(
j
<
ps
.
length
()
-
1
)
{
if
(
k
==
-
1
||
p
[
j
]
==
p
[
k
])
{
next
[++
j
]
=
++
k
;
}
else
k
=
next
[
k
];
//此语句是这段代码最反人类的地方,如果你一下子就能看懂,那么请允许我称呼你一声大神!
}
return
next
;
}
}
algorithm/wei/zhuanhuan.java
浏览文件 @
5e322493
...
...
@@ -59,6 +59,4 @@ public class zhuanhuan {
}
return
count
;
}
}
\ No newline at end of file
algorithm/进制转换/进制转换.java
浏览文件 @
5e322493
...
...
@@ -3,7 +3,7 @@ package 进制转换;
public
class
进制转换
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
Integer
.
toBinaryString
(
123
));
System
.
out
.
println
(
change
(
123
,
2
));
System
.
out
.
println
(
change
(
123
,
2
));
}
public
static
char
[]
arr
=
{
'a'
,
'b'
};
...
...
@@ -41,4 +41,43 @@ public class 进制转换 {
}
}
}
/**
* @param n 需要转的10进制数字
*/
public
static
void
Ten转16进制
(
int
n
)
{
char
[]
arr
=
new
char
[
2576
];
int
cur
=
n
;
int
count
=
0
;
while
(
cur
!=
0
)
{
if
(
cur
%
16
>=
10
)
arr
[
count
++]
=
(
char
)
(
cur
%
16
-
10
+
'A'
);
else
arr
[
count
++]
=
(
char
)
(
cur
%
16
+
'0'
);
cur
/=
16
;
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
count
-
1
;
i
>=
0
;
i
--)
{
sb
.
append
(
arr
[
i
]);
}
System
.
out
.
println
(
sb
);
}
/**
* @param n 需要转的16进制数
*/
public
static
void
Sixto10进制
(
String
n
)
{
long
res
=
0
;
int
t
=
0
;
int
c
=
0
;
for
(
int
i
=
n
.
length
()
-
1
;
i
>=
0
;
i
--)
{
if
(
n
.
charAt
(
i
)
>=
'A'
)
{
t
=
n
.
charAt
(
i
)
-
'A'
+
10
;
}
else
{
t
=
n
.
charAt
(
i
)
-
'0'
;
}
res
+=
t
*
Math
.
pow
(
16
,
c
++);
}
System
.
out
.
println
(
res
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录