C++中n條線的最大交點數


在本教程中,我們將討論一個尋找 n 條線的最大交點數的程式

為此,我們將提供一些直線。我們的任務是找到給定數量的線所滿足的最大交點數。

示例

 線上演示

#include <bits/stdc++.h>
using namespace std;
#define ll long int
//finding maximum intersection points
ll countMaxIntersect(ll n) {
   return (n) * (n - 1) / 2;
}
int main() {
   ll n = 8;
   cout << countMaxIntersect(n) << endl;
   return 0;
}

輸出

28

更新時間:09-09-2020

159 次瀏覽

開啟你的 職業生涯

透過完成該課程取得認證

開始使用
廣告
© . All rights reserved.