You are given _N_ qubits which are guaranteed to be in one of two basis states on _N_ qubits. You are also given two bitstrings _bits_0 and _bits_1 which describe these basis states.
Your task is to perform necessary operations and measurements to figure out which state it was and to return 0 if it was the state described with _bits_0 or 1 if it was the state described with _bits_1. The state of the qubits after the operations does not matter.
## Input
You have to implement an operation which takes the following inputs:
* an array of qubits _qs_,
* two arrays of boolean values _bits_0 and _bits_1, representing the basis states in which the qubits can be. These arrays will have the same length as the array of qubits. _bits_0 and _bits_1 will differ in at least one position.
An array of boolean values represents a basis state as follows: the _i_\-th element of the array is true if the _i_\-th qubit is in state , and false if it is in state . For example, array \[true; false\] describes 2-qubit state .
Your code should have the following signature:
namespace Solution {
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Canon;
operation Solve (qs : Qubit\[\], bits0 : Bool\[\], bits1 : Bool\[\]) : Int
{
body
{
// your code here
}
}
}
[samples]
你被给定 #cf_span[N] 个量子比特,它们保证处于以下两种基态之一:#cf_span[N] 个量子比特的两种基态。你还被给定两个比特串 #cf_span[bits0] 和 #cf_span[bits1],它们描述了这两种基态。
你的任务是执行必要的操作和测量,以确定当前处于哪种状态,并在状态为 #cf_span[bits0] 描述的状态时返回 0,在状态为 #cf_span[bits1] 描述的状态时返回 1。操作后量子比特的状态无关紧要。
你需要实现一个操作,它接收以下输入:
一个布尔值数组,以如下方式表示基态:数组的第 #cf_span[i] 个元素为 true 表示第 #cf_span[i] 个量子比特处于 状态,false 表示处于 状态。例如,数组 [true; false] 描述的是 2-量子比特状态 。
## Input
你需要实现一个操作,它接收以下输入:一个量子比特数组 #cf_span[qs],以及两个布尔值数组 #cf_span[bits0] 和 #cf_span[bits1],分别表示量子比特可能处于的基态。这些数组的长度与量子比特数组相同。#cf_span[bits0] 和 #cf_span[bits1] 至少在一个位置上不同。一个布尔值数组以如下方式表示基态:数组的第 #cf_span[i] 个元素为 true 表示第 #cf_span[i] 个量子比特处于 状态,false 表示处于 状态。例如,数组 [true; false] 描述的是 2-量子比特状态 。你的代码应具有以下签名:namespace Solution { open Microsoft.Quantum.Primitive; open Microsoft.Quantum.Canon; operation Solve (qs : Qubit[], bits0 : Bool[], bits1 : Bool[]) : Int { body { // your code here } }}
[samples]
**Definitions**
Let $ N \in \mathbb{Z}^+ $ be the number of qubits.
Let $ b_0, b_1 \in \{0,1\}^N $ be two distinct bitstrings representing orthonormal computational basis states:
- $ b_0 = (b_{0,1}, b_{0,2}, \dots, b_{0,N}) $, where $ b_{0,i} \in \{0,1\} $
- $ b_1 = (b_{1,1}, b_{1,2}, \dots, b_{1,N}) $, where $ b_{1,i} \in \{0,1\} $
The system is prepared in one of the two states: $ |b_0\rangle $ or $ |b_1\rangle $.
**Constraints**
1. $ b_0 \ne b_1 $
2. The input state is guaranteed to be exactly $ |b_0\rangle $ or $ |b_1\rangle $ (no superposition or noise).
**Objective**
Design a quantum operation that, given access to a single copy of the unknown state $ |\psi\rangle \in \{ |b_0\rangle, |b_1\rangle \} $, outputs:
$$
\begin{cases}
0 & \text{if } |\psi\rangle = |b_0\rangle \\
1 & \text{if } |\psi\rangle = |b_1\rangle
\end{cases}
$$
using quantum gates and measurement in the computational basis. The final state of the qubits after measurement is irrelevant.