returnA[j];
else if ( j - beg >= K ) // 否则,如果小于pivot的数目大于K-1个,则返回该部分中第K大的数
returnquickSelect( A, beg, j-1, K );
else
returnquickSelect( A, j1, end, K-(j-beg1) );
}
int main()
{
//freopen("a.txt","r",stdin);
int a[]={34,34,4234,8,445,6481,2387,123,86,514};
cout<<quickSelect(a,0,10,8)<<endl;
return 0;
}
输出结果:
2387
#include<iostream>
using namespace std;
int binary(int *a,int n,int key)
{
int l=0,r=n;
while(l<r)
{
int mid=l(r-l)/2; //避免(lr)溢出
if(a[mid]==key)
return mid;
if(a[mid]<key)
l=mid1;
else
r=mid;
}
return -1;
}
int main()
{
int a[]={1,3,4,5,6,7,8};
cout<<binary(a,7,7)1<<endl; //因为是从0开始的
return 0;
}
1. 半周长 P=(abc)/2
2. 面积 S=aHa/2=absin(C)/2=sqrt(P(P-a)(P-b)(P-c))
3. 中线 Ma=sqrt(2(b^2c^2)-a^2)/2=sqrt(b^2c^22bccos(A))/2
4. 角平分线 Ta=sqrt(bc((bc)^2-a^2))/(bc)=2bccos(A/2)/(bc)
5. 高线 Ha=bsin(C)=csin(B)=sqrt(b^2-((a^2b^2-c^2)/(2a))^2)
6. 内切圆半径 r=S/P=asin(B/2)sin(C/2)/sin((BC)/2)
=4Rsin(A/2)sin(B/2)sin(C/2)=sqrt((P-a)(P-b)(P-c)/P)
=Ptan(A/2)tan(B/2)tan(C/2)
7. 外接圆半径 R=abc/(4S)=a/(2sin(A))=b/(2sin(B))=c/(2sin(C))
D1,D2为对角线,M对角线中点连线,A为对角线夹角
1. a^2b^2c^2d^2=D1^2D2^24M^2
2. S=D1D2sin(A)/2
(以下对圆的内接四边形)
3. acbd=D1D2
4. S=sqrt((P-a)(P-b)(P-c)(P-d)),P为半周长
R为外接圆半径,r为内切圆半径
1. 中心角 A=2PI/n
2. 内角 C=(n-2)PI/n
3. 边长 a=2sqrt(R^2-r^2)=2Rsin(A/2)=2rtan(A/2)
4. 面积 S=nar/2=nr^2tan(A/2)=nR^2sin(A)/2=na^2/(4tan(A/2))
1. 弧长 l=rA
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34960-24.html
面对的不光是日本还有美国