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,找不到错误,那位大牛来帮帮忙?

Posted by idonotknow at 2009-05-13 22:10:40 on Problem 1182
#include<iostream>
using namespace std;
int pre[50010],kind[50010];
int g1,g2;
int find(int x,int reme)
{
    int _x,h=x;
    int s,sign=0;
    while(pre[h]!=h)
    {
          sign=(sign+kind[h])%3;
          h=pre[h];
    }
    s=sign;
    while(pre[x]!=x)
    {
          _x=pre[x];
          pre[x]=h;
          kind[x]=s;
          s=(3-kind[_x]+s)%3;
          x=_x;
    }
    if(reme==1) g1=sign;
    else g2=sign;
    return h;
}
int main()
{
    int cas,n,i,d,x,y,num=0,_x,_y;
    scanf("%d%d",&cas,&n);
    for(i=1;i<=cas;i++) 
    {
          pre[i]=i;
          kind[i]=0;
    }
    for(i=0;i<n;i++)
    {
          scanf("%d%d%d",&d,&x,&y);
          if(x>cas || y>cas)   num++;
          else if(d==2 && (x==y)) num++;
          else 
          {
               _x=find(x,1);_y=find(y,2);
               if(_x!=_y)  {pre[_x]=_y;kind[_x]=(2+d-g1+g2)%3;}
               else if(d==1 && g1!=g2)  num++;
               else if(d==2 && (3-g2+g1)%3!=1)  num++;
          }
    }
    printf("%d\n",num);
    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