C++程式計算圖的邊覆蓋
給定圖的n個頂點,任務是計算圖的邊覆蓋。邊覆蓋是指找到覆蓋圖中每個頂點的最小邊數。
例如,我們有n = 5
那麼它的圖將如下所示:

所以它的邊覆蓋是3

讓我們再舉一個n為8的例子

它的邊覆蓋將是:4

示例
Input: n= 5 Output: 3 Input: n= 8 Output: 4
下面使用的方案如下:
- 從使用者處獲取輸入
- 找到頂點數除以2.0的結果的上限值。
- 返回並列印結果。
演算法
Start Step 1-> declare function to calculate the edge cover of a graph int edge(int n) set float val = 0 set val = ceil(n / 2.0) return val step 2-> In main() set int n = 10 call edge(n) Stop
示例
#include <bits/stdc++.h>
using namespace std;
// Function to calculates Edge Cover
int edge(int n) {
float val = 0;
val = ceil(n / 2.0);
return val;
}
int main() {
int n = 10;
cout<<"minium number of edges required are :"<<edge(n);
return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出
minium number of edges required are :5
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP