0

这是来自 spoj 的摩天大楼楼层问题。当我运行代码时,我得到了 SIGABRT。问题的链接是http://www.spoj.com/problems/SCRAPER/。当我在我的 PC 上运行此代码时,它运行时没有任何错误,但 spoj 的在线判断显示 SIGABRT 错误。

#include <iostream>
#include <vector>
using namespace std;
struct floor
{
    unsigned int floornum;
    bool calldone;
    vector <floor*> connection;
    floor()
    {
        floornum=0;
        calldone=0;
    }


};
struct elevator
{
    unsigned int x,y;
    elevator()
    {
        x=y=0;
    }
};
struct skyscrapper
{
    unsigned int f,e,a,b;
    vector <elevator> ele;

    vector <floor*> flooraddress; //this is a spoj problem


    void read()
    {
        cin>>f>>e>>a>>b;

        elevator *temp;
        for(unsigned int i=0;i<e;i++)
        {
            temp=new elevator;
            cin>>(*temp).x>>(*temp).y;
            ele.push_back(*temp);
        }
        for (unsigned int i=0;i<f;i++)
        {
            floor* tempp=new floor;
            (*tempp).floornum=i;
            flooraddress.push_back(tempp);

        }
    }
    void allotaddress()
    {

        unsigned int j,k;
        for(unsigned int i=0;i<ele.size();i++)
        {
             j=ele[i].y;
             k=ele[i].x;
            while(j<f)
            {

                if(j!=ele[i].y)
                {
                (*(flooraddress[j])).connection.push_back(flooraddress[j-k]);

                (*(flooraddress[j-k])).connection.push_back(flooraddress[j]);
                }
                j=j+k;
            }
        }
    }



};
bool flag;

bool traverse(floor* m,int destination)
    {
    if((*m).calldone==1)
    {
        return 0;
    }   
    (*m).calldone=1;    
        if((*m).floornum==destination)
        return 1;
        if((*m).connection.empty())
        return 0;

        for(int i=0;i<(*m).connection.size();i++)
        {
             flag=traverse(((*m).connection[i]),destination);
            if(flag==1)
            return flag;
        }
        return 0;
    }

int main()
{
    int n;
    cin>>n;
    skyscrapper iit[n];
    bool ans[n];
    for(int i=0;i<n;i++)
    {
    iit[i].read();
    iit[i].allotaddress();
    ans[i]=traverse(iit[i].flooraddress[iit[i].a],iit[i].b);

}
for(int i=0;i<n;i++)
{
    if(ans[i]==1)
    cout<<"It is possible to move the furniture."<<endl;
    else
    cout<<"The furniture cannot be moved."<<endl;
}
    return 0;
}
4

0 回答 0