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 tcxgsy at 2005-11-13 11:12:31 on Problem 2726
#include"iostream"
using namespace std;
#define max 100000
int main()
{ int a[max][2];
  int i,n,k,sum,j,m;
  while(cin>>n&&n!=0)
  { for(i=1;i<=n;i++)
      cin>>a[i][0]>>a[i][1];
    k=0;m=-1;
  for(i=1;i<=n;i++)
  {	 sum=0;
	  for(j=1;j<=n;j++)
         if(j!=i)
		 { if(a[i][0]>a[j][0]&&a[i][1]>a[j][1])
		             break;
		 }
		 if(j==n+1) sum++;
        
		for(j=1;j<=n;j++)
         if(j!=i)
		 { if(a[i][1]>a[j][1]&&a[i][0]>a[j][0])
		             break;
		 }
		 if(j==n+1) sum++;
		 
  }
  cout<<sum<<endl;
  }
  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