![](https://imgsa.baidu.com/forum/w%3D580/sign=687d50a70723dd542173a760e108b3df/9ff97b310a55b31948aaaeb64da98226cefc175f.jpg)
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include<algorithm>
using namespace std;
int main(int argc, const char * argv[])
{
//我的思路大概就是随机生成4个0~360的数,判断是否有差值大于180的,如果有,则说明他们在同侧。
int times=50000;
int duck=4;
long long yes=0,no=0;
double right,a[365],max=0;
srand((int)time(0));
for(int j=0;j<times;j++)
{
for (int i = 0; i <=duck; i++) {
a[i]=(360*(rand()/32767.0));
}
sort(a,a+10);
for (int i=0;i<duck; i++) {
cout<<a[i]<<"\t\t";
}
//cout<<" <"<<a[0]<<"."<<a[duck-1]<<"> ";
//这里开始计算角度差值
max=(a[1]-a[0]);
for (int i=1; i<duck; i++) {
if(max<(a[i+1]-a[i]))
max=(a[i+1]-a[i]);
}
// 最小角度+360和最大角度比较
if(max<(a[0]+360-a[duck-1]))
max=(a[0]+360-a[duck-1]);
cout<<" Max: "<<max<<"\t\t";
// 算到这里结束
if((max)>180){
cout<<"Yes"<<endl;
yes++;
}
else {
cout<<"No"<<endl;
no++;
}
}
cout<<"Yes: "<<yes<<" No: "<<no<<endl;
right=yes;
cout<<(right/times);
return 0;
}