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 zjut020 at 2009-11-18 21:45:46 on Problem 2726
In Reply To:几个月前看过,但就是想不明白,今天一见,其实是很简单的题! Posted by:alpc47 at 2008-09-30 16:14:31
唉...传说中楼教主5min过的题..搞了一小时..

#include<iostream>
#include<algorithm>
using namespace std;
bool is[10000];
struct node{
int x,y,index;       
}nod[10000];
bool cmpx(node n1,node n2)
{
    return n1.x<n2.x;     
}
bool cmpy(node n1,node n2)
{
    return n1.y<n2.y;     
}
int main()
{
  //freopen("0.txt","r",stdin);
   //freopen("1.txt","w",stdout);
   int n,i; ////
   while(scanf("%d",&n)+1&&n){
       for(i=0;i<n;i++){
          scanf("%d%d",&nod[i].x,&nod[i].y);
          nod[i].index=i;
       }memset(is,0,sizeof(is));
       sort(nod,nod+n,cmpx);
       int minn=0x7fffffff,temp=0x7fffffff;
       for(i=0;i<n;i++){
           if(nod[i].y>=minn)is[nod[i].index]=1;
           if(i!=n-1&&nod[i].x==nod[i+1].x){
                temp=min(temp,nod[i].y);                                
           }
           else{
                minn=min(minn,min(temp,nod[i].y));     
           }                
       } 
       sort(nod,nod+n,cmpy);
       minn=0x7fffffff,temp=0x7fffffff;
       for(i=0;i<n;i++){
           if(nod[i].x>=minn)is[nod[i].index]=1;
           if(i!=n-1&&nod[i].y==nod[i+1].y){
                temp=min(temp,nod[i].x);                                
           }
           else{
                minn=min(minn,min(temp,nod[i].x));     
           }                
       } int sum=0;
       for(i=0;i<n;i++)if(!is[i])sum++;
       printf("%d\n",sum);                         
   }   
}

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