• 【例题 6-1 UVA


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

    在这里输入题意

    【题解】

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

    【代码】

    #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;
    }
    
  • 相关阅读:
    弄懂JDK、JRE和JVM到底是什么
    精选Java面试题(二)
    精选Java面试题
    HttpPost请求将json作为请求体传入的简单处理方法
    Python在for循环中更改list值的方法
    vue 图片加载失败时,加载默认图片
    移动端,进入页面前空白,添加加载状态
    img 失效时 显示默认图片
    vue 全局组件的引用
    页面到达底部,加载更多
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7693060.html
Copyright © 2020-2023  润新知