ZOJ3870 Team Formation

Source: Internet
Author: User

1 /**2 Author:oliver3 problemid:zoj3870 Team Formation4 */5 /*6 Ideas7 1. Xor operation, use ^ will explode, think of binary;8 2. We can try to simulate a previous one ^ so long as the current bit result becomes larger;9 3. How do we use the binary system in general? Since it's going to explode, we'll save 1 of our position.Ten 4. How does the problem exist and how do I use it?  One 5. What I thought before was that every 1 of each number was saved, but that was not how to avoid the repetitive calculations. Take a look at someone else's blog and try to save up to 1 of the maximum number of bits per digit.  A 6. Think about why it is the highest position . - 7. Well, now is not to put all the high 1 are saved, and then we up (1,n) to the original and the remainder of the steps to change into and bin[] operation.  - What we want is to become bigger than max{a,b}. Then look at the bigger one, then we'll look for a larger number, and this time we're not counting and comparing, but comparing to the top of the rest.  the Note that we should be able to think of a violent way to go through the past, to do the optimization, that is, each time just add can and this team to complete the number of good.  - Note that this does not have duplicates (like A and b,b and a), not so. Because there is no discovery, each time is a traversal of this number is max{a,b}.  - Note that we are a one-man move backwards until 0->1.  - step can not write? The idea is very detailed.  + * - #include <cstdio> + #include <cstring> A #include <algorithm> at  - using namespace std; -  - const int MAXM = 100000+10; - int bin[100]; - int A[MAXM]; in int main () - { to int t,n; + scanf ("%d", &t); - While (t--) the { * memset (bin,0,sizeof bin); $ scanf ("%d", &n);Panax Notoginseng int X; - for (int i=0;i<n;i++) the { + scanf ("%d", &a[i]); A X=a[i]; the for (int j=31;j>=0;j--)//here if you start from 32, you try what happens. + if (x& (1<<j)) {//extract highest bit - bin[j]++; $ Break ; $ }  - }  - long long ans=0; the Int J; - for (int i=0;i<n;i++)Wuyi { the X=a[i]; - For (j=31;j>=0;j--) Wu if (x& (1<<J)) break; - For (; j>=0;j--)//bin[] Operations About if (! ( x& (1<<J))) { $ Ans+=bin[j]; - }  - } -  A printf ("%lld\n", ans); + }     the }

2015-04-29 22:30:05

ZOJ3870 Team Formation

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.