zoukankan
html css js c++ java
google编程挑战赛Round1的前两道题
差了一点,看来的确不适合这项运动了。
public
int
chooseSeat(String row)
{
int
[] min
=
new
int
[row.Length];
for
(
int
i
=
0
;i
<
row.Length
-
1
;i
++
)
{
min[i]
=
IsOk(row,i);
}
int
j
=-
1
;
int
mine
=-
1
;
for
(
int
i
=
0
;i
<
row.Length
-
1
;i
++
)
{
if
(min[i]
>
mine)
{
j
=
i;
mine
=
min[i];
}
}
return
j;
}
public
int
IsOk(
string
row,
int
i)
{
if
(row[i]
!=
'
X
'
&&
row[i
+
1
]
!=
'
X
'
)
{
int
l1
=
i;
int
l2
=
row.Length
-
i
-
1
;
return
l1
<
l2
?
l1:l2;
}
else
return
-
1
;
}
public
int
cover(
int
[] heights)
{
if
(heights.Length
==
1
)
return
1
;
int
imax
=-
1
;
int
max
=-
1
;
for
(
int
i
=
0
;i
<
heights.Length;i
++
)
{
if
(heights[i]
>
max)
{
imax
=
i;
max
=
heights[i];
}
}
if
(lbstate(heights,imax)
==-
1
)
{
heights[imax]
--
;
return
cover(heights);
}
if
(lbstate(heights,imax)
==
1
)
{
heights[imax]
--
;
return
cover(heights)
+
1
;
}
if
(lbstate(heights,imax)
==
0
)
{
int
[] h2
=
new
int
[heights.Length
-
1
];
int
j
=
0
;
for
(
int
i
=
0
;i
<
heights.Length;i
++
)
{
if
(i
!=
imax
+
1
)
{
h2[j]
=
heights[i];
j
++
;
}
}
return
cover(h2);
}
return
0
;
}
public
int
lbstate(
int
[] h,
int
idx)
{
if
(idx
-
1
>=
0
)
{
if
(h[idx
-
1
]
==
h[idx])
return
0
;
}
if
(idx
+
1
<
h.Length)
{
if
(h[idx
+
1
]
==
h[idx])
return
0
;
}
if
(idx
-
1
>=
0
)
{
if
(h[idx
-
1
]
==
h[idx]
-
1
)
return
1
;
}
if
(idx
+
1
<
h.Length)
{
if
(h[idx
+
1
]
==
h[idx]
-
1
)
return
1
;
}
return
-
1
;
}
查看全文
相关阅读:
vscode 前端好用插件汇总
IE8和IE9下textarea滚动选中的问题
javascript实现数字整数位每三位一个逗号分隔
简单枚举(算法竞赛入门经典)
拓扑排序(算法竞赛入门经典)
七桥问题--欧拉(算法竞赛入门经典)
走迷宫问题 算法竞赛入门经典
ZOJ1008
ZOJ1163
HDU 1069 Monkey and Banana
原文地址:https://www.cnblogs.com/jetz/p/300541.html
最新文章
C#后台调用前台js(RegisterStartupScript)
jquery 筛选器
微信获取code
cross-document message 跨文档通信 HTML5
原生 drag drop HTML5
高性能 内存 事件优化
高性能 AJAX
高性能 建议 实践
判断是否为整数 整数判断
获取图片原始尺寸
热门文章
判断图片是否加载完成
indexed database IndexedDB
web storage 离线存储
JS正则表达式验证
HTML转义字符
vue2.0组件间数据传递
openlayers素材网站
vue特效网站集锦
IE播放音频踩坑之路---待修改
less与sass的区别
Copyright © 2011-2022 走看看