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
;
}
查看全文
相关阅读:
HDU 1849 Rabbit and Grass
HDU 1848 Fibonacci again and again
HDU 1847 Good Luck in CET-4 Everybody!
HDU 1846 Brave Game
HDU 1387 Team Queue
HDU 1870 愚人节的礼物
HDU 1509 Windows Message Queue
HDU 4381 Grid
HDU 5800 To My Girlfriend
HDU 5806 NanoApe Loves Sequence Ⅱ
原文地址:https://www.cnblogs.com/jetz/p/300541.html
最新文章
条款18:让接口容易被正确使用,不宜被误用。
条款17:以独立的语句将资源置入智能指针。
条款16:成对使用new以及delete的时候应该采取相同的形式
LeetCode OJ:Perfect Squares(完美平方)
LeetCode OJ:3Sum Closest(最接近的三数之和)
条款15:在资源管理类中提供对原始资源的访问
条款14:在资源管理类中小型coping的行为
条款13:以对象管理资源
HDU 3415 Max Sum of Max-K-sub-sequence
Noip2007提高组总结
热门文章
Noip2008提高组总结
在机场等船
Noip2009提高组总结
雨祭
Noip2010提高组总结
HDU 1575 Tr A
HDU 1851 A Simple Game
HDU 2147 kiki's game
HDU 2188 悼念512汶川大地震遇难同胞——选拔志愿者
HDU 1850 Being a Good Boy in Spring Festival
Copyright © 2011-2022 走看看