HDOJ 5017 Ellipsoid

第一次尝试模拟退火.....

Ellipsoid

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 916    Accepted Submission(s): 305

Special Judge

Problem Description

Given a 3-dimension ellipsoid(椭球面)

your task is to find the minimal distance between the original point (0,0,0) and points on the ellipsoid. The distance between two points (x1,y1,z1) and (x2,y2,z2) is defined as 

Input

There are multiple test cases. Please process till EOF.

For each testcase, one line contains 6 real number a,b,c(0 < a,b,c,< 1),d,e,f(0 ≤ d,e,f < 1), as described above. It is guaranteed that the input data forms a ellipsoid.All numbers are fit in double.

Output

For each test contains one line. Describes the minimal distance. Answer will be considered as correct if their absolute error is less than 10-5.

Sample Input

1 0.04 0.01 0 0 0

Sample Output

1.0000000

Source

2014 ACM/ICPC Asia Regional Xi‘an Online

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const double eps=1e-8;
const double r=0.99;
const int dir_x[8]={0,0,1,-1,1,-1,1,-1};
const int dir_y[8]={1,-1,0,0,-1,1,1,-1};

double a,b,c,d,e,f;

double DIST(double x,double y,double z)
{
	return sqrt(x*x+y*y+z*z);
}

double getZ(double x,double y)
{
	double A=c,B=e*x+d*y,C=a*x*x+b*y*y+f*x*y-1;
	double delta=B*B-4*A*C;
	if(delta<0) return 1e60;
	double z1=(-B+sqrt(delta))/2/A;
	double z2=(-B-sqrt(delta))/2/A;
	if(z1*z1<z2*z2) return z1;
	return z2;
}

double solve()
{
	double step=1;
	double x=0,y=0,z;
	while(step>eps)
	{
		z=getZ(x,y);
		for(int i=0;i<8;i++)
		{
			double nx=x+dir_x[i]*step;
			double ny=y+dir_y[i]*step;
			double nz=getZ(nx,ny);
			if(nz>1e30) continue;
			if(DIST(nx,ny,nz)<DIST(x,y,z))
			{
				x=nx;y=ny;z=nz;
			}
		}
		step=step*r;
	}
	return DIST(x,y,z);
}

int main()
{
	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
	{
		printf("%.8lf\n",solve());
	}
	return 0;
}
时间: 2024-11-13 08:19:08

HDOJ 5017 Ellipsoid的相关文章

hdu 5017 Ellipsoid(三分)

题目链接:hdu 5017 Ellipsoid 题目大意:给定一个面的方程,问在面上距离原点的最小值. 解题思路:三分套三分,先三分x,对于每个x,三分y,求出的最优解作为当前x的值. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double INF = 10000; const double eps

HDU 5017 Ellipsoid(西安网络赛K题)

HDU 5017 Ellipsoid 题目链接 思路:模拟退火大法好! 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int D[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}; dou

hdu 5017 Ellipsoid(西安网络赛 1011)

Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 850    Accepted Submission(s): 271 Special Judge Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minima

HDU 5017 Ellipsoid (计算几何,模拟退火)

Ellipsoid Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distance between the original point (0,0,0) and points on the ellipsoid. The distance between two points (x1,y1,z1) and (x2,y2,z2) is defined as  Input

hdu 5017 Ellipsoid(模拟退火)

Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1140    Accepted Submission(s): 412 Special Judge Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minim

HDU - 5017 Ellipsoid(模拟退火法)

Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distance between the original point (0,0,0) and points on the ellipsoid. The distance between two points (x1,y1,z1) and (x2,y2,z2) is defined as  Input There are

HDU 5017 Ellipsoid 模拟退火

网赛的时候感觉可以用模拟退火搞但是不会写,今天学了一下感觉模拟退火本身也不是很难= = #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; const double eps = 1e-8; const double r = 0.99; //降温速度 const int dx[] = { 0, 0, 1, -1, 1, -

【HDOJ】4328 Cut the cake

将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector>

POJ Xiangqi 4001 &amp;&amp; HDOJ 4121 Xiangqi

题目链接(POJ):http://poj.org/problem?id=4001 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=4121 Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1108   Accepted: 299 Description Xiangqi is one of the most popular two-player boa