首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

UVA 540 TLE ,多谢~

2013-10-13 
UVA 540 TLE 求助,谢谢~~http://uva.onlinejudge.org/index.php?optioncom_onlinejudge&Itemid8&pagesh

UVA 540 TLE 求助,谢谢~~
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=103&problem=481&mosmsg=Submission+received+with+ID+12489532
这道题我用了三种方法都是超时。。。不知道是哪里错了,求各位大神提点下,或者给出一个错误的例子,谢谢大家了。。。

#include<algorithm>
#include<iostream>
#include<iterator>
#include<cstring>
#include<string>
#include<map>
#include<list>

using namespace std;
map<int,int> arry;
list<int> team;
int tag[1050];

int main()
{
    int t=0,n;
    while(cin>>n&&n)
    {
        memset(tag,0,sizeof(tag));
        arry.clear();
        team.clear();
        int i,j,k,m,s;
        for(i=0;i<n;i++)
        {
            cin>>m;
            for(j=0;j<m;j++)
            {
                cin>>s;
                arry.insert(make_pair(s,i));
            }
        }
        cout<<"Scenario #"<<++t<<endl;
        string str;
        int p,q;
        map<int,int>::iterator pos;
        while(cin>>str&&str!="STOP")
        {
            if(str=="ENQUEUE")
            {
                cin>>k;
                pos=arry.find(k);
                p=pos->second;
                if(tag[p]==0)
                {
                    team.push_back(k);
                    tag[p]++;
                }
                else
                {
                    pos=arry.find(team.back());
                    q=pos->second;
                    list<int>::iterator iter=team.end();
                    iter--;
                    while(1)
                    {
                        if(p==q) break;
                        iter--;
                        pos=arry.find(*iter);
                        q=pos->second;
                    }
                    iter++;
                    team.insert(iter,k);
                    tag[p]++;
                }
            }
            else if(str=="DEQUEUE")
            {


                pos=arry.find(team.front());
                int d=pos->second;
                tag[d]--;
                cout<<team.front()<<endl;
                team.pop_front();
            }
        }
    }
    return 0;
}




map c++ UVA
[解决办法]
引用:
Quote: 引用:

哦不对。说了最多1k。那也一样吃瘪。20w个命令*1k你看要多久

map里搜索不是线性次数搜索啊,是对数次搜索啊

那你while(1)里是搜什么

热点排行