MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / main

Function main

codes/cpp/Code_3_08_1.cpp:7–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5long long N, X, A[1000009];
6
7int main() {
8 // ����
9 cin >> N >> X;
10 for (int i = 1; i <= N; i++) cin >> A[i];
11
12 // �z��̃\�[�g
13 sort(A + 1, A + N + 1);
14
15 // �񕪒T��
16 int left = 1, right = N;
17 while (left <= right) {
18 int mid = (left + right) / 2; // �T���͈͂̒����ŕ�������
19 if (A[mid] == X) { cout << "Yes" << endl; return 0; }
20 if (A[mid] > X) right = mid - 1; // �T���͈͂�O�������ɍi��
21 if (A[mid] < X) left = mid + 1; // �T���͈͂��㔼�����ɍi��
22 }
23
24 // �T���͈͂��Ȃ��Ȃ��Ă� Yes �ƂȂ�Ȃ���Γ����� No
25 cout << "No" << endl;
26 return 0;
27}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected