Codeforces Beta Round #2 C. Commentator problem 计算几何 + 模拟退火

C. Commentator problem

在这里插入图片描述

solution

找点一个点使得,该点与三个圆的切线夹角都相等。找点问题,用模拟退火.
让每个 α \alpha α (6个) 都相等即找到D点.

在这里插入图片描述

code

/*SiberianSquirrel*//*CuteKiloFish*/
#include <bits/stdc++.h>
//#include<bits/extc++.h>
#include<ext/rope>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define Inv(x) quick_pow(x, mod - 2)
#define Polynomial vector<int>
#define DEBUG(x, y) cout << x << ": " << y << '\n';
#define mem(a, x) memset(a, x, sizeof a)
#define right_1_pos(x) __builtin_ffs(x)
#define left_0_num(x) __builtin_clz(x)
#define right_0_num(x) __builtin_ctz(x)
#define num_of_1(x) __builtin_popcount(x)
#define Pii pair<int, int>
#define mp_(x, y) make_pair(x, y)
#define all(v) (v).begin(), (v).end()
using ld = long double;
using ll = long long;
//using ill = __int128;
using ull = unsigned long long;
using i16 = short;
const ld pi = acos(-1.0);
const ld eps = 1e-5;
const ll mod = 998244353, mod_g = 3, img = 86583718;
int inv2, inv3;
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> tr;
/*
 rb_tree_tag 和 splay_tree_tag 选择树的类型(红黑树和伸展树)
null_type//无映射(g++为null_mapped_type)
less<pii>//从小到大排序
tree_order_statistics_node_update//更新方式
tr.insert(mp_(x, y));//插入
tr.erase(mp_(x, y));//删除
tr.order_of_key(pii(x, y));//求排名
tr.find_by_order(x);//找k小值,返回迭代器
tr.join(b);//将b并入tr,前提是两棵树类型一致并且二没有重复元素
tr.split(v, b);//分裂,key小于等于v的元素属于tr,其余属于b
tr.lower_bound(x);//返回第一个大于等于x的元素的迭代器
tr.upper_bound(x);//返回第一个大于x的元素的迭代器
以上的所有操作的时间复杂度均为O(logn)
注意,插入的元素会去重,如set
*/
//-----------------------------------------------------------------IO Template
namespace StandardIO {
    template<typename T> inline void read(T &x) {
        x = 0; T f = 1;
        char c = getchar();
        for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
        for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
        x *= f;
    }

    template<typename T> inline void write(T x) {
        if (x < 0) putchar('-'), x *= -1;
        if (x >= 10) write(x / 10);
        putchar(x % 10 + '0');
    }
}
using namespace StandardIO;
// -------------------------------------------------------------------------------BASIC_MATH
namespace BASIC_MATH {
    ll mul(ll a, ll b) { ll z = (long double) a / mod * b; ll res = (unsigned long long) a * b - (unsigned long long) z * mod; return (res + mod) % mod; }
    // O(1) quick_mul, use long double
    inline ll quick_pow(ll ans, ll p, ll res = 1) {
        for(; p; p >>= 1, ans = mul(ans, ans) % mod)
            if(p & 1) res = mul(res, ans) % mod;
        return res % mod;
    }
    double gcd(double a,double b) {
        if(fabs(b) < eps) return a;
        if(fabs(a) < eps) return b;
        return gcd(b, fmod(a,b));
    }
    int gcd(int a, int b) { return __gcd(a, b); }
    ll gcd(ll a, ll b) { return __gcd(a, b); }
}
using namespace BASIC_MATH;

int sgn(double x) {
    if(fabs(x) < eps)return 0;
    if(x < 0)return -1;
    else return 1;
}
struct Point {
    double x,y;
    Point() {}
    Point(double _x,double _y) {
        x = _x;
        y = _y;
    }
    void input() {
        cin >> x >> y;
    }
    void output() {
        cout << fixed << setprecision(10) << x << ' ' << y << '\n';
    }
    bool operator == (Point b)const {
        return sgn(x-b.x) == 0 && sgn(y-b.y) == 0;
    }
    bool operator < (Point b)const {
        return sgn(x-b.x)== 0?sgn(y-b.y)<0:x<b.x;
    }
    Point operator -(const Point &b)const {
        return Point(x-b.x,y-b.y);
    }
    double operator ^(const Point &b)const {//叉积
        return x*b.y - y*b.x;
    }
    double operator *(const Point &b)const {//点积
        return x*b.x + y*b.y;
    }
    double distance(Point p) {	//返回两点的距离
        return hypot(x-p.x,y-p.y);
    }
    Point operator +(const Point &b)const {
        return Point(x+b.x,y+b.y);
    }
    Point operator *(const double &k)const {
        return Point(x*k,y*k);
    }
    Point operator /(const double &k)const {
        return Point(x/k,y/k);
    }
};
struct circle {
    Point p; double r;
    circle() {}
    circle(Point _p,double _r) {
        p = _p;
        r = _r;
    }
    circle(double x,double y,double _r) {
        p = Point(x,y);
        r = _r;
    }
    void input() { p.input(); cin >> r; }
};

circle c[4];
Point p;

double dx[4]={0, 1, 0, -1},
       dy[4]={1, 0, -1, 0};

double calc(Point a) {
    double dif = 0, d[3];
    for(int i = 0; i < 3; ++ i)
        d[i] = a.distance(c[i].p) / c[i].r;
    for(int i = 0; i < 3; ++ i)
        for(int j = i + 1; j < 3; ++ j)
            dif += (d[i] - d[j]) * (d[i] - d[j]);
    return dif;
}
void solve() {
    double dis = 1.0, now, t;
    for(int i = 0; i < 3; ++ i) {
        c[i].input();
        p = p + c[i].p;
    }
    p = p / 3.0;
    while(dis > eps) {
        now = calc(p);
        int best = -1;
        for(int i = 0; i < 4; ++ i) {
            t = calc(p + Point(dis * dx[i], dis * dy[i]));
            if(now > t) {
                now = t;
                best = i;
            }
        }
        if(best == -1) dis = 0.7 * dis;
        else p = p + Point(dis * dx[best], dis * dy[best]);

    }
    if(calc(p) < eps) p.output();
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
    signed test_index_for_debug = 1;
    char acm_local_for_debug = 0;
    do {
        if (acm_local_for_debug == '$') exit(0);
        if (test_index_for_debug > 20)
            throw runtime_error("Check the stdin!!!");
        auto start_clock_for_debug = clock();
        solve();
        auto end_clock_for_debug = clock();
        cout << "Test " << test_index_for_debug << " successful!" << endl;
        cerr << "Test " << test_index_for_debug++ << " Run Time: "
             << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
    solve();
#endif
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值