zoukankan      html  css  js  c++  java
  • 爬格子呀5-7

    暴力求解???
    代码如下:

    #include<cstdio>
    #include<iostream>
    #include<queue>
    
    using namespace std;
    int job[10];
    int n, time = 0, id;
    queue<int>s;
    
    //判断是否在存在优先级更高的元素;
    bool check(int now_id) {
        bool sign = true;
        for (int j = now_id + 1; j < n; j++) {
            if (job[j] != 0) 
                return sign = false;
            else
                return sign;
        }
    }
    
    //从首位一直计算到id;
    void to_id() {
        int kase = 0, m;
        while (kase++ < id) {
            m = s.front();
            s.pop();
            if (check(m)) {
                time++;
                job[m]--;
            }
            else {
                s.push(m);
            }
        }
    }
    
    //递归调用,计算时间的(仅记录思路用,请忽略)
    /*
    void cal_time(int now_id) {
        int kase = now_id, m;
        if (check(kase)) {
            m = s.front();
            kase = 0;
            cal_time(kase++);
        }
    }
    */
    
    int main() {
        cin >> n;
        int t = 0, k, id;
        while (t++ < n) {
            cin >> k;
            s.push(k);
            job[k]++;
        }
        cin >> id;
        int m;
        //单独判断;
        while (1) {
            m = s.front();
            s.pop();
            if (check(m)) {
                time++;
                break;
            }
            else {
                s.push(m);
                to_id();
            }
        }
        cout << time << endl;
        return 0;
    }
    
  • 相关阅读:
    索引与完整性约束(note6)
    数据库查询语句(note4)
    select 查询(note3)
    数据库创建(note2)
    mysql(note1)
    day 05
    day 04 字符串
    博文索引
    ubuntu+xen的编译
    hexo+github搭建个人网站
  • 原文地址:https://www.cnblogs.com/romaLzhih/p/9489859.html
Copyright © 2011-2022 走看看