English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
配列の双音性は以下の語法定義されています-
配列の双音性を要素に基づいて検索することは-
Bitonicity = 0 , initially arr[0] i from 0 to n Bitonicity = Bitonicity+1 ; if arr[i] > arr[i-1] Bitonicity = Bitonicity-1 ; if arr[i] < arr[i-1] Bitonicity = Bitonicity ; if arr[i] = arr[i-1]
配列の双音性を検索するコードでは、配列の現在の要素と前の要素の比較に基づいて変数を変更するための変数「双音性」を使用しています。上記のロジックは配列の双音を更新し、最終的な双音は配列の最後に見つけることができます。
#include <iostream> using namespace std; int main() { int arr[] = { 1, 2, 4, 5, 4, 3 }; int n = sizeof(arr) / sizeof(arr[0]); int Bitonicity = 0; for (int i = 1; i < n; i++) { if (arr[i] > arr[i - 1] Bitonicity++; else if (arr[i] < arr[i - 1]) Bitonicity--; } cout << "Bitonicity = " << Bitonicity; return 0; }
出力結果
Bitonicity = 1