Bestcoder R44 p3 hdu 5270 ZYB loves Xor II

Source: Internet
Author: User

This is last night teammates told me the question, do not know what was the fantasy incident occurred, I saw 22 multiplied by the XOR tangled for a long time do not know what to do

This morning read this question, found that 22 added XOR and then think about last night's idea found can do

For XOR in my memory, most of it is split into digits to do

So the question .... Actually, it's kind of like

Split into digits. There are two ways to split the data into digits and to split the answer into digital digits (in fact, every person who considers the answer)

Think about splitting the data into digital

Can't think of each individual's ' work ' alone

Then we'll think about every one of those answers.

The best thing to think about is the first place.

Only 1+0 can get 1, which is the number of a B array 1 and 0,

Where's the 2nd place? If the value of the first two bits of the two array is not less than 2^1 and less than 2^2, it is OK. Isn't his 2nd place 1?

And so on,,, the number of each digit 1 ...

Start writing code

Wa

Think about why you tried it. 1 1 3 3 This group of data found that the answer was 4 and thought,

In consideration of 2nd place, 2=<ai+bi<4 | | 6=<ai+bi<8 is right,,,

And so on,

Wrong again,,, what's the matter?

After confirming the algorithm right, and looking at the input and output,

Long time no problem.

1#include <iostream>2#include <cstdio>3#include <string.h>4#include <algorithm>5 6 #defineCL (b) memset (A,b,sizeof (a))7 #definell Long Long8 #defineull unsigned long Long9 using namespacestd;Ten  One #defineMAXN 200005 A  - ull AA[MAXN],BB[MAXN]; - ull TAA[MAXN],TBB[MAXN]; theUll cc[ -],be[ -],en[ -]; - intN; -  - voidINITCC () + { -CL (CC,0); +cc[0]=1; Abe[0]=1; aten[0]=2; -      for(intI=1; i<= +; i++) -     { -cc[i]=cc[i-1]*2+1; -be[i]=be[i-1]*2; -en[i]=en[i-1]*2; in     } - //for (int i=0;i<62;i++) printf ("%i64d%i64d%i64d\n", Cc[i],be[i],en[i]); to } +  - intMain () the { * INITCC (); $     intTt,ii;Panax NotoginsengCin>>tt; -Ii=0; the      while(tt--) +     { Ascanf"%d",&n); the         inti,j,k; +          for(i=0; i<n;i++) scanf ("%llu",&aa[i]); -          for(i=0; i<n;i++) scanf ("%llu",&bb[i]); $Ull res=0, BITC; $         intS1,s2,e1,e2; -          for(k=0;k< +; k++) -         { the              for(i=0; i<n;i++) -             {Wuyitaa[i]=aa[i]&Cc[k]; thetbb[i]=bb[i]&Cc[k]; -             } WuSort (taa,taa+n); -Sort (tbb,tbb+n); Abouts1=n-1; e1=n-1; bitc=0; $s2=n-1; e2=n-1; -              for(i=0; i<n;i++) -             { -                  while(s1>=0&AMP;&AMP;TBB[S1]+TAA[I]&GT;=BE[K]) s1--; A                  while(e1>=0&AMP;&AMP;TBB[E1]+TAA[I]&GT;=EN[K]) e1--; +  the                  while(s2>=0&AMP;&AMP;TBB[S2]+TAA[I]&GT;=BE[K]+EN[K]) s2--; -                  while(e2>=0&&tbb[e2]+taa[i]>=en[k+1]) e2--; $  theBitc+=e1-S1; thebitc+=e2-S2; the             } the  -res+=be[k]* (bitc%2); in         } theprintf"Case #%d:%llu\n",++ii,res); the     } About     return 0; the}

g++ does not support I64d???

No words changed the input and output

Finally AC

Bestcoder R44 p3 hdu 5270 ZYB loves Xor II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.