首页 > 其他 > 详细

Codeforces 583 DIV2 Robot's Task 贪心

时间:2015-10-04 20:48:13      阅读:339      评论:0      收藏:0      [点我收藏+]

原题链接: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=0;
int ans=0;
int d=1;

bool used[MAX_N];

int main() {
    cin.sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)cin >> a[i];
    int x = 0;
    while (cnt != n) {
        if (cnt >= a[x] && used[x] == 0) {
            cnt++;
            used[x] = 1;
        }
        if (cnt == n)break;
        x += d;
        if (x == n) {
            x = n - 2;
            d = -1;
            ans++;
        }
        if (x == -1) {
            x = 1;
            d = 1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

 

Codeforces 583 DIV2 Robot's Task 贪心

原文:http://www.cnblogs.com/HarryGuo2012/p/4854890.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!