谁说一下xor 在pascal的具体运用的例子

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:11:30
谁说一下xor 在pascal的具体运用的例子

最好有例题。

USACO的6.1节中的cow xor比较经典:
Cow XOR
Adrian Vladu -- 2005
Farmer John is stuck with another problem while feeding his cows. All of his N (1 ≤ N ≤ 100,000) cows (numbered 1..N) are lined up in front of the barn, sorted by their rank in their social hierarchy. Cow #1 has the highest rank; cow #N has the least rank. Every cow had additionally been assigned a non-unique integer number in the range 0..(221 - 1).

Help FJ choose which cows will be fed first by selecting a sequence of consecutive cows in the line such that the bitwise "xor" between their assigned numbers has the maximum value. If there are several such sequences, choose the sequence for which its last cow has the highest rank. If there still is a tie, choose the shortest sequence.

PROGRAM NAME: cowxor
INPUT FORMAT
Line 1: A single integer N
Lines 2..N+1: N integers ranging from 0 to 221 - 1, representing the cows' assigned numbers. Line j describes cow of soci