标签:getc etc print can scanf algorithm \n cstring 最大
又是一道只有计算右侧端点才能得出结果的题目
三分房顶的高度
用相似就可以计算出半径,然后再求最小体积就行了(千万不要求成最大体积)
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const double eps=1e-8; const double pi=3.1415926535898; inline int read(){ int x=0,f=1,ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } inline double max(double x,double y){ return x>y?x:y; } inline double cal_abs(double x){ return max(x,-x); } inline int dcmp(double x,double y){ double res=x-y; if(cal_abs(res)<eps) return 0; if(res<0) return -1; return 1; } int n; double l[10005],h[10005]; inline double cal(double x){ double r=0; for(int i=1;i<=n;i++) r=max(r,x*l[i]/(x-h[i])); return pi*r*r*x/3; } inline double cal1(double x){ double r=0; for(int i=1;i<=n;i++) r=max(r,x*l[i]/(x-h[i])); return r; } int main(){ int T=read(); while(T--){ n=read(); double sl=0,sr=999999999.0; for(int i=1;i<=n;i++){ double x,y,z; scanf("%lf %lf %lf",&x,&y,&z); // cout<<i<<"\t"<<n<<endl; l[i]=sqrt(x*x+y*y); h[i]=z;sl=max(sl,z); } // puts("x"); while(dcmp(sl,sr)<0){ double l1=(2*sl+sr)/3,r1=(sl+2*sr)/3; double res=dcmp(cal(l1),cal(r1)); if(res==0) sl=l1,sr=r1; if(res==-1) sr=r1; if(res==1) sl=l1; // cout<<sl<<"\t"<<sr<<endl; } printf("%.3lf %.3lf\n",sr,cal1(sr)); } return 0; }
标签:getc etc print can scanf algorithm \n cstring 最大
原文地址:https://www.cnblogs.com/gcyyzf/p/9689504.html