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

map 我崩溃了,为啥有的查不到呢

Posted by nuanran at 2008-10-28 02:47:55 on Problem 2002
比如第一个例子,明明遍历map的时候有(1,1),(0,0)这两个点,但是为啥find不到呢。。。
#include <stdio.h>
#include <string.h>
#include <map>

using namespace std;

struct Point
{
    int x;
    int y;
}point[2010],p1,p2;

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;
    }
};

int main()
{
    int n,count,i,j;
    map<Point,int,pointCmp> mapPoint;
    map<Point,int,pointCmp>::iterator iter1,iter2;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&point[i].x,&point[i].y);
            printf("%d %d %d\n",point[i].x,point[i].y,i);
            mapPoint.insert( make_pair ((Point)point[i],i));        
        }
        for(iter1=mapPoint.begin();iter1!=mapPoint.end();iter1++)
        {
            printf("%d--%d--%d--\n",iter1->first.x,iter1->first.y,iter1->second);
        }
        count=0;
        for(i=0;i<n;i++)
        {
            for(j=i+1;j<n;j++)
            {
                p1.x=point[i].x+point[j].x-point[i].y+point[j].y;
                p1.y=point[i].x-point[j].x+point[i].y+point[j].y;
                p2.x=point[i].x+point[j].x+point[i].y-point[j].y;
                p2.y=point[j].x-point[i].x+point[i].y+point[j].y;
                if(p1.x%2==0&&p1.y%2==0&&p2.x%2==0&&p2.y%2==0)
                {
                    p1.x/=2;
                    p1.y/=2;
                    p2.x/=2;
                    p2.y/=2;
                    printf("%d %d %d %d\n",p1.x,p1.y,p2.x,p2.y);
                    for(iter1=mapPoint.begin();iter1!=mapPoint.end();iter1++)
                    {
                        printf("%d %d %d\n",iter1->first.x,iter1->first.y,iter1->second);
            
                    }
                    printf("%d-----%d\n",p2.x,p2.y);
                    iter1=mapPoint.find((Point)p1);
                    if(iter1!=mapPoint.end()) printf("cc\n");
                    iter2=mapPoint.find((Point)p2);
                    if(iter2!=mapPoint.end()) printf("dd\n");
                    ///if(iter1!=mapPoint.end()) printf("dd\n");
                    if(iter1!=mapPoint.end()&&iter2!=mapPoint.end()) count++;
                }
            }
        }
        printf("%d\n",count/2);
    }
    return 0;
}


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