您的位置:首页 > 其它

cf#323-div2-B. Robot's Task-简单模拟

2015-10-04 13:18 447 查看
题意

给n,表示n台电脑,每台有一条信息

给ai表示,取第i台电脑需要已经得到ai条信息

要求取完所有电脑的信息

一开始在位置1,可以不断的向前走,移到不能往前时,可以转向

问最少转多少次方向。。。。

必然是一路走到尾。。。最后才转向,才会使得转的次数最少。。。直接无脑模拟就好。

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
int n;
int cun=0;

int tm[1005];
int vis[1005];
int dir=1; ///right

int need_turn(int x)
{
if (dir==1&&x==n)
return 1;
if (dir==0&&x==1)
return 1;
return 0;
}
int go(int x)
{
if (need_turn(x))
{
dir=!dir;
cun++;
}
if (dir==1)
return x+1;
else
return x-1;
}
int main()
{

int i,j;
scanf("%d",&n);
int a,b;
int sum=0;
for (i=1;i<=n;i++)
{
scanf("%d",&tm[i]);
sum+=tm[i];
}
int now=0;
for (i=1;i<=n&&i>=1;i=go(i) )
{
if (now==n)
break;
if (vis[i])
continue;

if (now>=tm[i])
{
now++;
vis[i]=1;
}
if (now==n)
break;
}
printf("%d\n",cun);
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: