http://poj.org/problem?id=3301
都说这个题是三分题目 但它不是单峰吧 好怀疑
我根据网上的代码写的 连第二组数据都过不了 但交上去 0ms 过啦
建议不要做这道题 如果有高手指点 那就跟好了
#include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<set> #include<cmath> #include<algorithm> using namespace std; const int N=1005; const double M=1000000.0; const double PI=acos(-1.0); const double eps=1e-10; int x[N]; int y[N]; double sidemax(double k,int n) { double x1,x2,y1,y2; x1=y1=M; x2=y2=-M; double xtemp,ytemp; for(int i=0;i<n;++i) { xtemp=x[i]*cos(k)-y[i]*sin(k); ytemp=y[i]*cos(k)+x[i]*sin(k); //cout<<xtemp<<" "<<ytemp<<endl; x1=min(x1,xtemp); x2=max(x2,xtemp); y1=min(y1,ytemp); y2=max(y2,ytemp); } //cout<<x1<<" "<<x2<<endl; return max(y2-y1,x2-x1); } int main() { //freopen("data.txt","r",stdin); int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i=0;i<n;++i) scanf("%d %d",&x[i],&y[i]); double l=0.0; double r=PI/2.0; //int I=0; while((r-l)>eps) { //cout<<++I<<endl; //cout<<l<<" TTTT "<<r<<endl; double mid=(r+l)/2.0; double midr=(mid+r)/2.0; if(sidemax(mid,n)<sidemax(midr,n)) { r=midr; }else { l=mid; } } printf("%.2f\n",sidemax(l,n)*sidemax(l,n)); } return 0; }