标签:des blog http io os ar for sp strong
---恢复内容开始---
Description
Input
Output
Sample Input
Sample Output
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #define esp 1e-7 using namespace std; bool flag; double a, b, c, d, e, f; double getz(double x, double y) { double A = c; double B = d*y + e*x; double C = f*x*y + a*x*x + b*y*y - 1.0; double v = B*B - 4*A*C; if (v < 0) { flag = 0; return 0; } flag = 1; v = sqrt(v); double z1 = (v-B) / A / 2.0; double z2 = (-v-B) / A / 2.0; if (fabs(z1) < fabs(z2)) return z1; else return z2; } double dis(double x, double y) { double z = getz(x, y); if (flag == 0) return 0; return sqrt(x*x + y*y + z*z); } double qt()//模拟退火 { double x = 0, y = 0, Min = dis(x, y); double xx, yy, len; double step = 1; while (step >= esp) { for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { if (dx == 0 && dy == 0) continue; xx = x + step*dx; yy = y + step*dy; len = dis(xx, yy); if (flag && len < Min) { Min = len; x = xx; y = yy; } } } step *= 0.97; } return Min; } int main() { //freopen("test.txt", "r", stdin); while (scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF) { printf("%.7lf\n", qt()); } return 0; }
ACM学习历程——HDU5017 Ellipsoid(模拟退火)(2014西安网赛K题)
标签:des blog http io os ar for sp strong
原文地址:http://www.cnblogs.com/andyqsmart/p/4067171.html