会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
サ繌н筻刂挭
博客园
首页
新随笔
联系
订阅
管理
HDU 1034 Candy Sharing Game
直接模拟。
用qsort排序后,当第一个学生和最后一个学生的糖果数相等时,结束游戏。
Code
#include
<
iostream
>
using
namespace
std;
int
now[
101
],pie[
101
];
int
cmp(
const
void
*
l,
const
void
*
r)
{
return
*
(
int
*
)l
-*
(
int
*
)r;
}
int
circle(
int
n)
{
int
result
=
0
;
while
(
1
)
{
qsort(now,n,
sizeof
(
int
),cmp);
if
(now[
0
]
==
now[n
-
1
])
break
;
for
(
int
i
=
0
;i
<
n;
++
i)
{
now[(i
+
1
)
%
n]
=
pie[(i
+
1
)
%
n]
/
2
+
pie[i]
/
2
;
if
(now[(i
+
1
)
%
n]
%
2
)
++
now[(i
+
1
)
%
n];
}
for
(
int
i
=
0
;i
<
n;
++
i)
pie[i]
=
now[i];
++
result;
}
return
result;
}
int
main()
{
int
n;
while
(cin
>>
n,n)
{
for
(
int
i
=
0
;i
<
n;
++
i)
{
cin
>>
pie[i];
now[i]
=
pie[i];
}
int
round
=
circle(n);
cout
<<
round
<<
"
"
<<
now[
0
]
<<
endl;
}
return
0
;
}
posted @
2009-04-28 16:03
黄浩贤
阅读(
184
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告