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 tzkq at 2010-02-21 23:14:06 on Problem 2002
In Reply To:map 我崩溃了,为啥有的查不到呢 Posted by:nuanran at 2008-10-28 02:47:55
struct pointCmp
{
    bool operator() (const Point p1,const Point p2) const
    {
        if(p1.x==p2.x) return p1.y-p2.y;
        return p1.x-p2.x;
    }
};

这里有问题, stl 中的比较器与 qsort所需要的不同.

qsort需要的是能判断<,>,=三种关系的比较器,因此返回值是int, 以正负零来区分

而stl中的sort与map等需要的是<比较器,只需要判断是否小于, 以true/false区分

所以这里可以改成

struct pointCmp
{
    bool operator() (const Point p1,const Point p2) const
    {
        if(p1.x==p2.x) return p1.y<p2.y;
        return p1.x<p2.x;
    }
};

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