会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
SDJL的足迹
首页
博问
闪存
管理
USACO_2_2_Runaround Numbers
没有用到什么特别的方法,从M+1开始一个一个的枚举
Code
/**/
/*
ID: sdjllyh1
PROG: runround
LANG: JAVA
complete date: 2008/12/14
author: LiuYongHui From GuiZhou University Of China
more article: www.cnblogs.com/sdjls
*/
import
java.io.
*
;
import
java.util.
*
;
public
class
runround
{
private
static
int
m;
private
static
int
answer;
public
static
void
main(String[] args)
throws
IOException
{
init();
run();
output();
System.exit(
0
);
}
private
static
void
run()
{
int
enumeration
=
m
+
1
;
while
(
!
isRunroundNumber(enumeration))
{
enumeration
++
;
}
answer
=
enumeration;
}
private
static
boolean
isRunroundNumber(
int
value)
{
int
length
=
Integer.toString(value).length();
int
[] digits
=
new
int
[length];
int
index
=
length;
while
(value
>
0
)
{
index
--
;
digits[index]
=
value
%
10
;
value
=
value
/
10
;
}
boolean
[] repeated
=
new
boolean
[
10
];
for
(
int
i
=
0
; i
<
length; i
++
)
{
if
(repeated[digits[i]])
{
return
false
;
}
else
{
repeated[digits[i]]
=
true
;
}
}
int
pointer
=
0
;
boolean
[] isTouched
=
new
boolean
[length];
for
(
int
i
=
0
; i
<
length; i
++
)
{
pointer
=
(pointer
+
digits[pointer])
%
length;
if
(isTouched[pointer])
{
return
false
;
}
else
{
isTouched[pointer]
=
true
;
}
}
return
true
;
}
private
static
void
init()
throws
IOException
{
BufferedReader f
=
new
BufferedReader(
new
FileReader(
"
runround.in
"
));
m
=
Integer.parseInt(f.readLine());
f.close();
}
private
static
void
output()
throws
IOException
{
PrintWriter out
=
new
PrintWriter(
new
BufferedWriter(
new
FileWriter(
"
runround.out
"
)));
out.println(answer);
out.close();
}
}
posted on
2008-12-15 14:38
刘永辉
阅读(
258
) 评论(
0
)
收藏
举报
刷新页面
返回顶部