Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

Maximum points of intersection n lines in C++


ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมหาจุดตัดสูงสุดของ n เส้นตรง

เราจะได้รับจำนวนเส้นตรง งานคือหาจำนวนจุดตัดสูงสุดที่จำนวนเส้นตรงที่กำหนดสามารถตัดกันได้

ตัวอย่างโค้ด

#include <bits/stdc++.h>
using namespace std;

#define ll long long

ll countMaxIntersect(ll n) {
    return n * (n - 1) / 2;
}

int main() {
    ll n = 8;
    cout << countMaxIntersect(n) << endl;
    return 0;
}

เอาต์พุต

28