zoukankan      html  css  js  c++  java
  • POJ2420 寻找费马点 模拟退火(不会)/三分套三分

    所谓的三分套三分 , 题意RT

    #include<iostream>
    #include<algorithm>
    #include<fstream>
    #include<string>
    #include<cmath>
    #include<cstring>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<sstream>
    #include<cstdio>
    #define INF 0x3f3f3f3f
    #define inf 0x7FFFFFFF
    #define MOD 100
    #define pii pair<int,int>
    #define eps 1e-6
    #define equals(a,b) (fabs(a-b)<eps)
    #define bug puts("bug")
    #define re  register
    const int maxn = 1e6 + 5;
    const double PI = acos(-1.0);
    typedef  long long ll;
    using namespace std;
    
    struct Point {
        double x, y;
        Point(){}
        Point(double _x,double _y):x(_x),y(_y){}
    };
    
    Point p[105];
    int n;
    
    double get_sum(double xx,double yy) {
        double res = 0;
        for (int i = 0; i < n; i++)  res += sqrt((xx - p[i].x) * (xx - p[i].x) + (yy - p[i].y) * (yy - p[i].y));
        return res;
    }
    
    double three(double x) {
        double l = 0.0, r = 10000.0;
        for (int i = 0; i < 100; i++) {
            double mid = (l + r) / 2;
            double mmid = (mid + r) / 2;
            if (get_sum(x, mid) < get_sum(x, mmid)) r = mmid;
            else l = mid;
        }
        return get_sum(x, l);
    }
    
    int main() {
        while (~scanf("%d", &n)) {
            for (int i = 0; i < n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
            double l = 0.0, r = 10000.0;
            for (int i = 0; i < 100; i++) {
                double mid = (l + r) / 2;
                double mmid = (mid + r) / 2;
                if (three(mid) < three(mmid)) r = mmid;
                else l = mid;
            }
            printf("%.0f\n", three(l));
        }
        return 0;
    }
  • 相关阅读:
    vector::reserve()对迭代器的影响
    C#日期格式转换大全
    aa
    C#中取到当前日期是在一年中的第几周
    EasyUI
    使用Ajax传递 json数据,并在一般处理页面进行接收全过程
    C#操作海量数据(Oracle、SQL Server)
    UE4教程
    游戏引擎的原理及应用
    C++基础02 (数组、函数、指针、结构体)
  • 原文地址:https://www.cnblogs.com/hznumqf/p/13021163.html
Copyright © 2011-2022 走看看