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 fanhqme at 2009-04-25 15:13:57 on Problem 1830
          scanf("%d",&N);
          S=0;
          for (int i=0;i<N;i++){
              scanf("%d",&x);
              S^=(x<<i);
          }
          for (int i=0;i<N;i++){
              scanf("%d",&x);
              S^=(x<<i);
          }
          for (int i=0;i<N;i++)A[i]=((S&(1<<i))&&1)+(1<<(i+1));
          while (scanf("%d %d",&x,&y),x+y)A[y-1]|=(1<<x);
          res=N;
          for (int i=0;i<N;i++){
              k=i;
              for (int j=i+1;j<N;j++)if (A[j]>A[k])k=j;
              x=A[i];A[i]=A[k];A[k]=x;
              if (A[i]<2){
                 res=i;
                 break;
              }
              for (int j=i+1;j<N;j++)if (HighestBit(A[i])==HighestBit(A[j]))A[j]^=A[i];
          }
          if (res<N && A[res])puts("Oh,it's impossible~!!");
          else printf("%d\n",1<<(N-res));

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