ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1218. Episode N-th: The Jedi Tournament

why crash ( access violation ) test #4
Posted by manishmmulani 5 Jan 2008 04:18
#include<iostream>
#include<string>
#include<vector>
using namespace std;

struct node
{
    string name;
    bool flag[205],temp[205];
    vector<int> winto;
    int count ;    long int x, y,z;

    bool canWinOver(struct node p)
    {
        int c=0;
        if( x > p.x ) c++;
        if( y > p.y ) c++;
        if( z > p.z ) c++;

        if( c > 1 ) return true;
        return false;
    }
};

typedef struct node node;

int main()
{
    node jedi[205] ; int i , j , n , k , l;
    string s;
    long int p,q,r;
    cin >> n;

    for(i=1 ; i <= n ; i++ )
    {
        cin >> s >> p >> q >> r;

        jedi[i].name=s;    jedi[i].x=p;    jedi[i].y=q;    jedi[i].z=r;
    }

    for(i=1; i <= n ; i++)
    {
        for(j=i+1; j <= n ; j++)
        {
            if( jedi[i].canWinOver(jedi[j]) )
            {    jedi[i].flag[j]=true;    jedi[i].winto.push_back(j);        jedi[i].count++;    }
            else
            {    jedi[j].flag[i]=true;    jedi[j].winto.push_back(i);        jedi[j].count++;    }
        }
    }

    for(i=1 ; i <= n ; i++ )
    {
        for(j=1 ; j <= n ; j++ )
        {
            if(i!=j && !(jedi[i].flag[j]) )
            {
                for(k=0 ; k < jedi[i].count ; k++ )
                {
                    l = jedi[i].winto[k];
                    if(!(jedi[j].flag[l]))
                    {    jedi[j].winto.push_back(l);         jedi[j].temp[l]=true;            }
                }
            }
        }
    }

    for(i=1 ; i <= n ; i++ )
    {
        int sum=0;
            for(j=1 ; j <= n ; j++ )
            if( jedi[i].flag[j] || jedi[i].temp[j] )    sum++;

        if(sum==n-1)
        cout << jedi[i].name << endl;
    }

        return 0;

}


PLS HELP