"Bzoj3105" "New Nim Game" "bzoj2460" "element"

Source: Internet
Author: User

3105: [cqoi2013] New NIM game

Time Limit:10 Sec Memory limit:128 MB
submit:585 solved:350
[Submit] [Status] [Discuss]
Description

The traditional NIM game is this: there are some match stacks, each with several matches (the number of matches in different heaps can be different). Two players take turns, each time you can choose a match heap to remove several matches. You can take one or the whole bunch of matches, but not from more than a dozen matches at the same time. The player who took the last match won.
The game is slightly different: in the first round, the first player can take a number of matches directly from the whole pile. Can not take a bunch of, but can not take all. The second round is also the same, the second player also has such an opportunity. Starting with the third turn (and the first player), the rules are the same as the Nim game.
If you take it first, how can you guarantee to win? If you can win, let the first round match the total number of matches as small as possible.

Input

The first behavior of the integer k. That is, the number of match stacks. The second line contains a positive integer of not more than 109 k, that is, the number of matches in each heap.

Output

Outputs the minimum number of matches taken in the first round. If there is no guarantee to win, output-1.
Sample Input

6

5 5 6 6 5 5

Sample Output

21st
HINT

k<=100

The condition of winning the winner is obviously that when you take away some elements, the rest of the set is also 0 or less between any elements.
So we can from the big to the small sort, greedy, can put in, not to put, then how to judge can put it?
We can use the linear base, we want to find the highest 1 in the binary, and then with all this one has 1 of the number also or, then do so, if the last number is not 0, it means that the number can be put in.

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;#define LL Long Longintn,a[101],b[101],c[101]={0}; LL ans=0, sum=0;BOOLcmpintXintY) {returnX>y;}intMain () {intI,j;scanf("%d", &n); for(i=1; i<=n;++i)scanf("%d", &a[i]); Sort (A +1, a+n+1, CMP); for(i=1; i<=n;++i) {b[i]=a[i];    sum=sum+ (LL) a[i]; } for(i=1; i<=n;++i) { for(j= in; ~j;--j)if(a[i]& (1&LT;&LT;J)) {if(!c[j]) {c[j]=i; Break; }ElseA[I]^=A[C[J]]; }if(A[i]) ans=ans+ (LL) b[i]; }printf("%lld\n", Sum-ans);}
2460: [BeiJing2011] Element

Time limit:20 Sec Memory limit:128 MB
submit:373 solved:199
[Submit] [Status] [Discuss]
Description

Legend has it that, in ancient times, on the Western continent of magic land, people have mastered the use of magic
The technique of refining a rod in a method of ore. It was then realized that the mana of a scepter depended on the ores used.
In general, the more ore the more powerful, but extremes meet: Sometimes, people in order to get stronger mana and
The use of a lot of ore, but in the refining process found that all the magic ore disappeared, so that can not be refined
Out of the staff, this phenomenon is called "magic Offset." In particular, if the refining process uses more than
A piece of the same ore, there is a certain "magic offset".
Later, with the improvement of people's cognitive level, this phenomenon has been well explained. After a lot of
After the experiment, the famous mage Dmitri found: If you are to make a reasonable compilation of every mineral found now
Number is a positive integer, called the element ordinal of the ore, an ore combination produces a "magic
"When and only if there is a non-empty set, the element ordinal of those ores varies by bit or up
to zero. (If you're not sure what the XOR is, see the next page for a noun explanation.) For example, use two
The same ore is bound to "magical offsets" because the elements of the two ores are of the same ordinal, different or
to zero.
And people have an effective way of measuring magic, already known: The magic of the crafting wand
is equal to the Falizhi and of each kind of ore. People have already measured the mana value of all the ores found today,
and the element number of each ore is calculated by experiment.
Now, given your ore information, please calculate the maximum number of staff that can be refined at that time.
How much magic is there.

Input

The first line contains a positive integer n, which represents the number of species of ore.
The next n lines, two positive integers per line, numberi and Magici, denote the element ordinal of this ore
and mana value.

Output

Package only one line, an integer: The maximum mana value

Sample Input

3

1 10

2 20

3 30

Sample Output

50

HINT

As a result of the "magic offset" the fact that each ore is used up to one piece.

If all three ores are used, because the element sequence of the three is different or up: 1 XOR 2 xor 3 = 0,

There will be magic offsets and no staves.

It can be found that the best option is to select the latter two ores, with Mana of 20+30=50.

For all data: n≤1000,numberi≤10^18

, magici≤10^4

Source

Day2

As in the above question, it is also or becomes the element ordinal, then adds the number to become the magic value to be OK.

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;#define LL Long Longintn,c[10001]={0};structS{ll No;intVA;} a[10001]; LL ans=0, sum=0;BOOLCMP (S x,s y) {returnX.va==y.va?x.no>y.no:x.va>y.va;}intMain () {intI,j,x;scanf("%d", &n); for(i=1; i<=n;++i)scanf("%lld%d", &a[i].    No,&a[i].va); Sort (A +1, a+n+1, CMP); for(i=1; i<=n;++i) { for(j= $; ~j;--j)if((a[i). NO&GT;&GT;J) &1){if(!c[j]) {c[j]=i; Break; }ElseA[i]. NO^=A[C[J]].          No; }if(A[i].    No) ans=ans+ (LL) A[i].va; }printf("%lld\n", ans);}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Bzoj3105" "New Nim Game" "bzoj2460" "element"

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.