V
Vladimir Ralev
Bad stuff happens lately. I almost skrewed it up on a programming
contest yesterday. I tried few runs with this code (testing), it
behaved well, until test 59(or something). Means - doing pretty well
... But then - (on gcc) i get segmentation failure. Turned on stl
debugging symbols (on VC)...and i got something called DAMAGE ERROR
after normal block #57. After 40 minutes of mad code scramble i
managed to get it str8, but i still cant figure out what is that
error. I can only say it has something to do with memory allocation
checks in debug stl builds.
Thanks for any comments on that! It almost got me and costed me 40
minutes for such a simple program.
#include<vector>
#include<algorithm>
using namespace std;
struct offbandp
{
int offnum;
int closerto;
bool biggre;
};
bool operator< (const offbandp &s1,const offbandp &s2)
{
if(s1.closerto==s2.closerto) return s1.biggre;//bug here?note biggre
*is* bool
//fix:if(s1.closerto==s2.closerto) return s1.biggre>s2.biggre;
return s1.closerto<s2.closerto;
}
class SkipRope
{
public:
vector <int> partners(vector <int> candidates, int height)
{
int q=0;
vector<offbandp> vecstr(candidates.size());
for(q=0;q<vecstr.size();q++)
{
vecstr[q].closerto=abs(height-candidates[q]);
vecstr[q].offnum=q;
vecstr[q].biggre=int(height<candidates[q]);
}
sort(vecstr.begin(),vecstr.end()); <- DAMAGE ERROR here
vector<int> res(2);
int a=vecstr[0].offnum,b=vecstr[1].offnum;
res[0]=candidates[vecstr[0].offnum];
res[1]=candidates[vecstr[1].offnum];
sort(res.begin(),res.end());
return res;
}
};
void main()
{
int test[]={82, 105, 112, 147, 112, 77, 93, 127, 158, 95, 151, 139,
103, 103, 174, 112, 95, 108, 109, 162, 164, 118, 119, 121, 156, 150,
169, 127, 171, 102, 123, 149, 132, 108, 83, 148, 174};
vector<int> test2(test,test+sizeof(test)/sizeof(int));
SkipRope t;t.partners(test2,99);
}
contest yesterday. I tried few runs with this code (testing), it
behaved well, until test 59(or something). Means - doing pretty well
... But then - (on gcc) i get segmentation failure. Turned on stl
debugging symbols (on VC)...and i got something called DAMAGE ERROR
after normal block #57. After 40 minutes of mad code scramble i
managed to get it str8, but i still cant figure out what is that
error. I can only say it has something to do with memory allocation
checks in debug stl builds.
Thanks for any comments on that! It almost got me and costed me 40
minutes for such a simple program.
#include<vector>
#include<algorithm>
using namespace std;
struct offbandp
{
int offnum;
int closerto;
bool biggre;
};
bool operator< (const offbandp &s1,const offbandp &s2)
{
if(s1.closerto==s2.closerto) return s1.biggre;//bug here?note biggre
*is* bool
//fix:if(s1.closerto==s2.closerto) return s1.biggre>s2.biggre;
return s1.closerto<s2.closerto;
}
class SkipRope
{
public:
vector <int> partners(vector <int> candidates, int height)
{
int q=0;
vector<offbandp> vecstr(candidates.size());
for(q=0;q<vecstr.size();q++)
{
vecstr[q].closerto=abs(height-candidates[q]);
vecstr[q].offnum=q;
vecstr[q].biggre=int(height<candidates[q]);
}
sort(vecstr.begin(),vecstr.end()); <- DAMAGE ERROR here
vector<int> res(2);
int a=vecstr[0].offnum,b=vecstr[1].offnum;
res[0]=candidates[vecstr[0].offnum];
res[1]=candidates[vecstr[1].offnum];
sort(res.begin(),res.end());
return res;
}
};
void main()
{
int test[]={82, 105, 112, 147, 112, 77, 93, 127, 158, 95, 151, 139,
103, 103, 174, 112, 95, 108, 109, 162, 164, 118, 119, 121, 156, 150,
169, 127, 171, 102, 123, 149, 132, 108, 83, 148, 174};
vector<int> test2(test,test+sizeof(test)/sizeof(int));
SkipRope t;t.partners(test2,99);
}