【例题 6-1 UVA - 210】Concurrency Simulator

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


队列模拟题。
注意初始化。。
然后题目中是让读入一个数据组数然后再输入数据的。
但样例。。但样例没有!?

【代码】

#include <bits/stdc++.h>
using namespace std;

const int P = 5;
const int N = 10;
const int L = 25;

int n,t[P+5],Q;
string Pro[N + 10][L + 10];
int lines[N + 10],cur[N+10];
deque <int> dl;
queue <int> blocked;
bool flag = 0,ru;
int val[300];

void run(int idx)
{
    int QAQ = 0;
    while (QAQ < Q)
    {
        cur[idx]++;
        switch (Pro[idx][cur[idx]][2])
        {
            case '=':
            {
                QAQ += t[1];
                int x;
                if (isdigit(Pro[idx][cur[idx]][5]))
                    x = (Pro[idx][cur[idx]][4] - '0') * 10 + (Pro[idx][cur[idx]][5] - '0');
                else
                    x = Pro[idx][cur[idx]][4] - '0';
                val[Pro[idx][cur[idx]][0]] = x;
                break;
            }

            case 'i'://print
            {
                QAQ += t[2];
                cout << idx << ": "<<val[Pro[idx][cur[idx]][6]] << endl;
                break;
            }

            case 'c'://lock
            {
                QAQ += t[3];
                if (!flag)
                    flag = 1;
                else
                {
                    ru = true;
                    blocked.push(idx);
                    cur[idx]--;
                    return;
                }
                break;
            }

            case 'l'://unlock
            {
                QAQ += t[4];
                flag = 0;
                if (!blocked.empty())
                {
                    dl.push_front(blocked.front());
                    blocked.pop();
                }
                break;
            }

            case 'd':
            {
                QAQ += t[5];
                return;
                break;
            }

            default:break;
        }
    }
}

int main()
{
    /*freopen("F:\\rush.txt", "r", stdin);
    freopen("F:\\rush_out.txt", "w", stdout);*/
    int kase = 0;
    int T;
    scanf("%d", &T);
    while (T--)
    {
        memset(val, 0, sizeof val);
        if (kase > 0) puts("");
        kase++;
        scanf("%d", &n);
        for (int i = 1; i <= 5; i++) scanf("%d", &t[i]);
        scanf("%d", &Q);
        getchar();
                for(int i=1;i<=10;i++) lines[i]=0;
                for(int i=1;i<=10;i++) cur[i]=0;
        for (int i = 1; i <= n; i++)
        {
            string s;
            while (getline(cin, s))
            {
                lines[i]++;
                Pro[i][lines[i]] = s;
                if (s =="end") break;
            }
        }

        while (!dl.empty()) dl.pop_back();
        while (!blocked.empty()) blocked.pop();
        flag = false;

        for (int i = 1; i <= n; i++) dl.push_back(i);

        while (!dl.empty())
        {
            ru = false;
            int x = dl.front();
            dl.pop_front();
            run(x);
            if (!ru && lines[x] > cur[x]) dl.push_back(x);
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7693060.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值