judge not compiling well

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
trulo17
Learning poster
Posts: 62
Joined: Mon Jan 24, 2005 6:12 am
Location: Lima,Peru

judge not compiling well

Post by trulo17 » Fri Feb 03, 2006 6:23 pm

Code: Select all

#include<cstdio>
#include<iostream>
#include<deque>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<queue>
#include<string>
#include<set>
#include<sstream>
#include<cmath>
#define inf 2000000000
using namespace std;
struct cosa
{
    int p,w;
};
struct cell
{
    int x,y;
};
struct orden
{
    bool operator()(cell a,cell b)
    {
        if(a.x<b.x||(a.x==b.x&&a.y<b.y))
            return true;
        return false;
    }
};
set<cell,orden> S;
int T[1001][31];
cosa A[1001];
int memo(int x,int y)
{    
    cell aux;
    aux.x=x;
    aux.y=y;
    if(S.find(aux)==S.end())
    {
        if(x==0||y==0)
            T[x][y]=0;
        else
        {
            if(A[x].w>y)
                T[x][y]=memo(x-1,y);
            else
                T[x][y]=max(memo(x-1,y),memo(x-1,y-A[x].w)+A[x].p);
        }
        S.insert(aux);
    }
    return T[x][y];
}
int main()
{
    int Test,test,n,m,i,j,k,total,x;
    scanf("%d",&Test);
    for(test=0;test<Test;++test)
    {
        scanf("%d",&n);
        for(i=1;i<=n;++i)
            scanf("%d%d",&A[i].p,&A[i].w);
        scanf("%d",&m);
        for(i=0,total=0;i<m;++i)
        {
            scanf("%d",&x);
            S.clear();
            total+=memo(n,x);
        }
        printf("%d\n",total);
    }
}
the code above is getting compile error, but it's compiling well at home and even in other judges!(i sent the code just to see if it compile and there was no problem).
I discovered that this line:

Code: Select all

if(S.find(aux)==S.end())
it's the reason for the compile error(i removed it and it got wa), but i dont' know why this is happening, i've used set.find() here before(with S.find(int),S.find(string),etc) but since i'm defining the struct, there should no be problem.thx in advance

User avatar
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba » Fri Feb 03, 2006 7:33 pm

operator() in orden should be const.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...

Post Reply

Return to “C++”