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
;
}
查看全文
相关阅读:
将博客搬至CSDN
神州笔记本电脑【K670D】安装 Ubuntu18.04 系列操作
ValueError: Unknown label type: 'continuous'
Spark: JAVA_HOME is not set
IDEA 搭建 Spark 源码 (Ubuntu)
XX-Net 解决IPV6 不稳定,时好时坏。
解决SBT下载慢,dump project structure from sbt?
pip install kaggle 出现 【网络不可达】?
Git clone 克隆Github上的仓库,速度慢?
进程间的通信方式
原文地址:https://www.cnblogs.com/jetz/p/300541.html
最新文章
一些有用的Python问题
CMAKE设置VS工程中Debug和Release不同的输出名称
CMAKE设置INSTALL工程,分别设置头文件、Lib和DLL的输出路径
计算vtkRender的屏幕坐标范围和物理坐标范围
VS2013编译64位boost流程及若干问题
QTableWidget中添加QPushButton
VTK删除vtkPolyData中的顶点和面片
std::sort排序时VS2013报错“Expression : invalid operator < ”的解决方法
网格缺陷检测:退化点、线、面的判断
wpf 使用了 template 了的 combobox 中,displaymemberpath 有 bug,仅在 popup 中生效
热门文章
C#找出可用TCP端口,仅两行代码就搞定
android studio真垃圾
web前端bug积累
lockable JS function,解锁操作之前,不能重复操作
插件开发
给MS的意见
C#: int 与 byte[] 互转
wpf 实现 css3 中 boxshadow inset 效果
找出点的密集区域,javascript实现,html5 canvas效果图
import tensorflow 出现非法指令(核心已转储)
Copyright © 2011-2022 走看看