|
楼主 |
发表于 2005-8-29 18:41:30
|
显示全部楼层
99年钻井布局B题的C\C++程序
<>#include<math.h><BR>#include<iostream.h><BR> const double demand=0.05,pi=3.1415926;<BR> float px[12],py[12],ax[12],by[12],<BR> x[]={0.50,1.41,3.00,3.37,3.40,4.72,4.72,5.43,7.57,8.38,8.98,9.50},<BR> y[]={2.00,3.50,1.50,3.51,5.50,2.00,6.24,4.10,2.01,4.50,3.41,0.80};<BR> int n,s,num,nearx[12],neary[12],w[12],well[12];<BR> void ChangeXY(int i,double a,double x1,double y1)<BR> {<BR> px=x1*cos(a*pi/180)-y1*sin(a*pi/180);<BR> py=x1*sin(a*pi/180)+y1*cos(a*pi/180);<BR> }<BR> float sqr(double p)<BR> {<BR> return p*p;<BR> }<BR> void main()<BR> {<BR> double dex,dey,a,a1,dex1,dey1;<BR> int i;<BR> cout<<"旧井的总数是:";<BR> cin>>n;<BR> s=0;<BR> for(a=0;a<=90;a+=0.01)//<BR> {<BR> for(i=0;i<12;i++)<BR> {<BR> ChangeXY(i,a,x,y);</P>
<> nearx=int(px);<BR> neary=int(py);<BR> if(px<0)<BR> {<BR> ax=abs(nearx)+px+1;<BR> }<BR> else ax=px-nearx;<BR> if(py<0)<BR> {<BR> by=abs(neary)+py+1;<BR> }<BR> else by=py-neary;<BR> }<BR> for(dex=0;dex<=1.0;dex+=0.01)//<BR> for(dey=0;dey<=1;dey+=0.01)//<BR> {<BR> for(i=0;i<n;i++) w=0;<BR> num=0;<BR> for(i=0;i<n;i++)<BR> {<BR> if(sqrt(sqr(ax-dex)+sqr(by-dey))<=demand)<BR> {<BR> num++; w=1;<BR> }<BR> }<BR> if(num>=s)<BR> { <BR> s=num; <BR> for(i=0;i<n;i++) well=w;<BR> a1=a;<BR> dex1=dex;<BR> dey1=dey;<BR> }<BR> }<BR> }//for(a=...)<BR> cout<<"可以利用的旧井序列号为:";<BR> for(i=0;i<n;i++) if(well) cout<<i+1<<" ";<BR> cout<<endl;<BR> cout<<"可以利用的旧井的总数为:"<<s<<endl; <BR> cout<<"原点是:("<<dex1<<","<<dey1<<")";<BR>}</P> |
|