如何找到一组点的最大三角形面积?

时间:2020-09-13 21:16:02

标签: c++

我正在尝试解决以下问题:-

Q)在方阵10个单位的正方形内部署100个随机点。接下来,对于具有中心和半径的给定圆(输入),找到点(在100个展开点中)是

(i)在输入圆的圆周上,

(ii)在圆圈内,并且

(iii)在圈子外。

此外,在圆(输入)内找到三角形最大的三个点(从100点开始)。 有人告诉我只考虑整数,也只考虑那些完全位于正方形内的整数。此外,我想补充一点,即可以采取两个观点。我编写了解决前三部分的代码,但无法弄清楚如何找到面积最大的三角形。

#include<iostream> 
#include<string> 
#include<cstdlib> 
#include<ctime>
using namespace std;
int main() { 

 int x[1000] ; 
 int y[1000] ; 

srand((unsigned int) time(0) ) ; 
for(int i = 0 ; i<= 99; i++){
    x[i] = rand()%9 + 1 ; 
    y[i] = rand()%9 + 1 ; 
} 

int x0, y0, r ;  

cin>>x0>>y0>>r ;  

cout<<" (i) Points which are on the perimeter of the circle are "<<endl ; 

for(int i = 0 ; i<=99 ; i++){

    if( (x[i] - x0)*(x[i] - x0) + (y[i] - y0)*(y[i] - y0) == r*r  ){
        cout<<'('<<x[i]<<','<<y[i]<<')'<<' ' ; 
    }

}  

cout<<endl<<" (ii) Points which are inside the circle are "<<endl ; 

for(int i = 0 ; i<=99 ; i++){

    if( (x[i] - x0)*(x[i] - x0) + (y[i] - y0)*(y[i] - y0) < r*r  ){
        cout <<'('<<x[i]<<','<<y[i]<<')'<<' ' ; 
    }

}  

cout<<endl<<" (iii) Points which are outside the circle are "<<endl ; 

for(int i = 0 ; i<=99 ; i++){

    if( (x[i] - x0)*(x[i] - x0) + (y[i] - y0)*(y[i] - y0) > r*r  ){
        cout <<'('<<x[i]<<','<<y[i]<<')'<<' ' ; 
    }

}  

cout<<endl ; 




return 0 ; }

有人可以告诉我如何在圆内找到形成最大三角形的点吗? O(n ^ 3)复杂度也可以。

0 个答案:

没有答案