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

请高手指教!WA了N次了.

Posted by wang28103 at 2008-03-14 13:09:26 on Problem 1308
#include <iostream>
 using namespace std;
 int main()
 {  int nodecount;
    int check[1000][2],flag[1000][2];
 	int countX(0),countY(0);
 	int pointX,pointY,number(0);
    int i,j;
 	cin >> pointX >> pointY;
    while(pointX>0||pointY>0)
 	{	int judge(0);

      	while( pointX != 0 || pointY != 0)
 		{
          flag[countX][0]=0;
          flag[countY][1]=0;
          check[countX++][0] = pointX;
 	      check[countY++][1] = pointY;
 	      cin >> pointX >> pointY;
 
 		}
        nodecount=2*countX;  
      	for( i = 0 ; i < countX ; ++i)
 		{
 		   for( j = i+1 ; j < countX ; ++j)
 		   {       
 			  if( (check[i][1] == check[j][1] && check[i][0] != check[j][0])|| (check[i][1] == check[j][0]&&check[i][0] == check[j][1]) ||(check[i][0] == check[i][1]) )
 			  {
 					judge = 1;
 					break;
 			  }
 			  if(i != j && check[i][0] == check[j][0] && check[i][1]==check[j][1])
 			  {
 			     judge = 1;
 				 break;
              }			   
 		   }		   
           
 			  if(judge) break;
 		}
 		for(i = 0 ; i < countX ; ++i)
 		{
 		   for(j = i+1 ; j < countX ; ++j)
 		   {  if(check[i][0]==check[j][0])
 		            flag[j][0]=-1;
 		      if(check[i][0]==check[j][1])
 		            flag[j][1]=-1;      
              if(check[i][1]==check[j][0])
 		            flag[j][0]=-1; 
           }
        }     
 		for(i=0;i<countX;i++)
 		 {  if(flag[i][0]==-1)
 		      nodecount--;
            if(flag[i][1]==-1)
              nodecount--;
         }
        if(nodecount!=countX+1)
           judge=1;
 		if(judge)
 			cout << "Case "<< ++number <<" is not a tree."<<endl;
 		else 
 		   cout << "Case " << ++number << " is a tree."<<endl;
        cin >> pointX >> pointY;
        countX=0;
        countY=0;
   }
  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