Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不知道哪里错了啊,有过了的人帮忙看看么

Posted by limoonbird at 2012-08-16 20:19:44 on Problem 2740
#include <iostream>
#include <deque>
#include <cstring>
#include <algorithm>
using namespace std;
deque<int> desks[20];
deque<int>::iterator pos;
int s[101][2];
int requests[101][51];
int request[10000];
int main()
{
    int m,c,n;
    cin>>m>>c>>n;
    while(m!=0)
    {
        memset(s,0,sizeof(s));
        for(int i=0;i<10;i++)
            desks[i].clear();
        int sum=0;
        for(int i=0;i<n;i++)
        {
            cin>>s[i][0];
            sum+=s[i][0];
            for(int j=0;j<s[i][0];j++)
                cin>>requests[i][j];
        }
        int index=0;
        while(index<sum)
            for(int i=0;i<n;i++)
            {
                if(s[i][1]<s[i][0] )
                    request[index++]=requests[i][s[i][1]++];
            }
        int SUM=0;
        for(int i=0;i<sum;i++)
        {
            int j=0;
            //在书桌上面找书,找不到就在书架上面拿
            for(j=0;j<m;j++)
                if((pos=find(desks[j].begin(),desks[j].end(),request[i]))!=desks[j].end())
                {
                    SUM+=j+1;
                    desks[j].erase(pos);
                    break;
                }
            if(j==m)
                SUM+=m+1;
            //放书
            //如果D1是未满的,就放在D1
            if(desks[0].size()<c)
            {
                desks[0].push_back(request[i]);
                SUM++;
            }
            else
            {
                //如果D1是满的,就先把书放到最近的非空桌子
                int index=-1;
                for(j=0;j<m;j++)
                    if(desks[j].size()<c)
                    {
                        desks[j].push_back(request[i]);
                        SUM+=j+1;
                        index=j;
                        break;
                    }
                if(j==m)
                {
                    SUM+=m+1;
                    index=m;
                }
                //拿起D1上面的最旧的书
                int old_book= desks[0].front();
                desks[0].pop_front();
                SUM++;
                //把最旧的书放在最近的非空桌子上面
                for(j=1;j<m;j++)
                    if(desks[j].size()<c)
                    {
                        desks[j].push_back(old_book);
                        SUM+=j+1;
                        break;
                    }
                if(j==m)
                {
                    SUM+=m+1;
                }
                //从临时位置上面把书拿回来
                if(index!=m)
                {
                    desks[index].pop_back();
                    SUM+=index+1;
                }
                else
                    SUM+=m+1;
                //重新放到新位置上面
                SUM++;
                desks[0].push_back(request[i]);
            }

        }

        cin>>m>>c>>n;
        cout<<SUM<<endl<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator