hdu 5017 模拟退火/三分求椭圆上离圆心最近的点的距离
http://acm.hdu.edu.cn/showproblem.php?pid=5017
求椭圆上离圆心最近的点的距离。
模拟退火和三分套三分都能解决
- #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, -1, 1, -1 };
- const int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
- double a, b, c, d, e, f;
- double dis(double x, double y, double z) {
- return sqrt(x * x + y * y + z * z);
- }
- //已知x,y,求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,
- z2 = (-B - sqrt(delta)) / 2 / A;
- if (z1 * z1 < z2 * z2) return z1;
- else 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 + dx[i] * step,
- ny = y + dy[i] * step,
- nz = getz(nx, ny);
- if (nz > 1e30) continue;
- if (dis(nx, ny, nz) < dis(x, y, z)) {
- x = nx; y = ny; z = nz;
- }
- }
- step *= r;
- }
- return dis(x, y, z);
- }
- int main() {
- while (scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF) {
- printf("%.8f\n", solve());
- }
- return 0;
- }
三分要比退火快
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cstring>
- #include <string>
- #include <queue>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define RD(x) scanf("%d",&x)
- #define RD2(x,y) scanf("%d%d",&x,&y)
- #define clr0(x) memset(x,0,sizeof(x))
- typedef long long LL;
- const double INF = 10000;
- const double eps = 1e-8;
- double solve(double a,double b,double c)
- {
- double delta = b*b-4.0*a*c;
- if(delta < eps)
- return INF;
- return (sqrt(delta)-b)/(a*2.0);
- }
- double a,b,c,d,e,f;
- double z(double x,double y)
- {
- double zz = solve(c,d*y+e*x,a*x*x+b*y*y+f*x*y-1);
- return x*x+y*y+zz*zz;
- }
- double y(double x)
- {
- double l = -INF,r = INF;
- int t = 200;
- while(l+eps<r){
- double mid = (l+r)/2,rr = (mid+r)/2;
- if(z(x,rr) < z(x,mid))
- l = mid;
- else
- r = rr;
- }
- return z(x,l);
- }
- double x()
- {
- double l = -INF,r = INF;
- int t = 200;
- while(l+eps<r){
- double mid = (l+r)/2,rr = (mid+r)/2;
- if(y(rr) < y(mid))
- l = mid;
- else
- r = rr;
- }
- return sqrt(y(l));
- }
- int main(){
- while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f))
- printf("%.8lf\n",x());
- return 0;
- }
hdu 5017 模拟退火/三分求椭圆上离圆心最近的点的距离的更多相关文章
- hdu 5017 模拟退火算法
hdu 5017 http://blog.csdn.net/mypsq/article/details/39340601 #include <cstdio> #include <cs ...
- hdu 5017 模拟退火
题意:给出椭球面的立体解析式,要求椭球面上距离原点最近的点的距离 sol:这题要想推公式就
- HDU - 5017 Ellipsoid(模拟退火法)
Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distance bet ...
- HDU 6362(求椭圆中矩形周长的期望 数学)
题意是给定一个椭圆标准方程的a,b(椭圆的长半轴长和短半轴长),在[0,b]内取一个数,则过点(0,b)且平行于x轴的直线与椭圆交于两点,再将此两点关于x轴做对称点,顺次连接此四点构成矩形,求出这些矩 ...
- HDU - 5017 Ellipsoid(模拟退火)
题意 给一个三维椭球面,求球面上距离原点最近的点.输出这个距离. 题解 模拟退火. 把\(z = f(x, y)\)函数写出来,这样通过随机抖动\(x\)和\(y\)坐标就能求出\(z\). 代码 / ...
- HDU 4355——Party All the Time——————【三分求最小和】
Party All the Time Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 4311 Meeting point-1 求一个点到其它点的曼哈顿距离之和
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4311 解题报告:在一个平面上有 n 个点,求一个点到其它的 n 个点的距离之和最小是多少. 首先不得不 ...
- HLJU 1221: 高考签到题 (三分求极值)
1221: 高考签到题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 9 Solved: 4 [Submit][id=1221">St ...
- BNU 4260 ——Trick or Treat——————【三分求抛物线顶点】
ial Judge Prev Submit Status Statistics Discuss Next Type: None None Graph Theory 2-SAT ...
随机推荐
- Access denied for user 'root'@'localhost' (using password:YES)解决方法
Access denied for user 'root'@'localhost' (using password:YES)解决方法 在MySQL的使用过程中,我们可能会碰到“Access denie ...
- android热门消息推送横向测评![转]
关于这个话题,已经不是什么新鲜事了.对于大多数中小型公司一般都是选择第三方的服务来实现.但是现在已经有很多提供推送服务的公司和产品,如何选择一个适合自己项目的服务呢?它们之间都有什么差别?在此为大家做 ...
- django通过url传递参数(编辑操作页面)
在做到编辑部分时,想到的办法是在编辑上跳转到页面时给他一个包含唯一标识id的url,然后通过这个url中的id去查询出该条数据,将数据内容显示在编辑页面. 1.编辑按钮 <button on ...
- .net 委托的用法
定义了两个委托 //Func有返回值:Action无返回值.两个委托 Func<int,int> f= a =>a+1;//参数,返回值: int reslut=f(5);//6
- cf-Round541-Div2-F(并查集+静态链表)
题目链接:http://codeforces.com/contest/1131/problem/F 思路: 很容易看出这是一道并查集的题目,因为要输出每个cage中住的鸟的编号,故采用静态链表.用l[ ...
- 注册google账号 解决国内手机注册失败的问题
1. PC端下载夜神安卓模拟器.安装,启动. 2. 在模拟器里的市场应用里下载qq邮箱. 3. 启动邮箱,选择gmail,注册.后续一切顺利. 这是迄今为止,唯一注册顺利的方法.其他方法,手机验证一关 ...
- .net的内置对象
一 . 获取客户端,服务器端信息: Response.Write("客户端信息:"); Response.Write("<br>浏览器类型,版本:" ...
- UVa 1592 Database(巧用map)
Peter studies the theory of relational databases. Table in the relational database consists of value ...
- 利用python计算windows全盘文件md5值的脚本
import hashlib import os import time import configparser import uuid def test_file_md5(file_path): t ...
- SQL时间格式化 转载备用~
Sel1 取值后格式化{0:d}小型:如2005-5-6{0:D}大型:如2005年5月6日{0:f}完整型 2 当前时间获取 DateTime.Now.ToShortDateString 3 取值中 ...