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

位运算+枚举 469ms

Posted by OOC at 2015-08-23 12:37:12 on Problem 2965
#include<stdio.h>
#include<iostream>
using namespace std;
int dir[16]={4383,8751,17487,34959,4593,8946,17652,35064,7953,12066,20292,36744,61713,61986,62532,63624};
int main()
{
      //  freopen("in","r",stdin);
        char ch;
        int va=0,minn=17,ans;
        for(int i=0;i<16;i++)
        {
                cin>>ch;
                if(ch=='+')
                        va+=1<<i;
        }
        for(int i=0;i<65536;i++)
        {
                int a=va,num=0;
                for(int j=0;j<16;j++)
                {
                        if(i&(1<<j))
                        {
                                a^=dir[j];
                                num++;
                        }
                }
                if(a==0)
                  if(num<minn)
                     {
                        minn=num;
                        ans=i;
                     }
        }
        printf("%d\n",minn);
        for(int i=0;i<16;i++)
                if(ans&(1<<i))
                        printf("%d %d\n",i/4+1,i-i/4*4+1);
}

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