问题描述:
有一个旅游团上山观光,沿着山路走到目的地。观光后原路返回
已知每上100米所用的体力为1,每下100米所用的体力为0.4
每使用3点体力就要停下来休息,并且到目的地观光的时候也是休息。
要预算中途休息的次数(不包含观光的那次)来准备干粮等。
问题解答:
#define PB_ID ct2_3
#include <stdio.h>
int main()
{
int iN =0;
long double lfCome = 0.0;
long double lfGo = 0.0;
int iPre, iNext;
int iCount = 0;
int iDifferent;
int iTime = 0;
while ((scanf("%d", &iN) != EOF) && (iN != 0))
{
lfCome = 0.0;
lfGo = 0.0;
iTime = 0;
iPre = 0;
for (iCount = 0; iCount < iN; ++iCount)
{
scanf("%d", &iNext);
iDifferent = iNext - iPre;
if (iDifferent >= 0)
{
lfCome += 0.01 * iDifferent;
lfGo += 0.004 * iDifferent;
}
else
{
lfCome += 0.004* (-iDifferent);
lfGo += 0.01 * (-iDifferent);
}
iPre = iNext;
}
iTime += (int)(lfCome / 3);
iTime += (int)(lfGo / 3);
if (iTime <= 1)
{
printf("%d time\n", iTime);
}
else
{
printf("%d times\n", iTime);
}
}
return 0;