原题链接:http://codeforces.com/problemset/problem/583/B
题意:
就。。要打开一个电脑,必须至少先打开其他若干电脑,每次转向有个花费,让你设计一个序列,使得总花费最小。
题解:
就傻傻的走就好。。从左走到右,再走回来,更新序列和答案就好。
代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define MAX_N 1003
using namespace std; int a[MAX_N];
int n; int cnt=;
int ans=;
int d=; bool used[MAX_N]; int main() {
cin.sync_with_stdio(false);
cin >> n;
for (int i = ; i < n; i++)cin >> a[i];
int x = ;
while (cnt != n) {
if (cnt >= a[x] && used[x] == ) {
cnt++;
used[x] = ;
}
if (cnt == n)break;
x += d;
if (x == n) {
x = n - ;
d = -;
ans++;
}
if (x == -) {
x = ;
d = ;
ans++;
}
}
cout << ans << endl;
return ;
}