zoukankan      html  css  js  c++  java
  • Codeforces 583 DIV2 Robot's Task 贪心

    原题链接: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;
    }
  • 相关阅读:
    王道训练营-C语言-1
    错排问题
    王道训练营-C语言-1
    图文处理 生成海报
    根据经纬度按距离排序
    vue总结
    docker+consul
    doker es
    知识库
    php笔记
  • 原文地址:https://www.cnblogs.com/HarryGuo2012/p/4854890.html
Copyright © 2011-2022 走看看