codeforces 2 C. Commentator problem(模拟退火)

题意:找一个点使这个点使这个点看三个圆的角度大小一样。

思路:模拟退火。初始化条件实在太难控制了。郁闷郁闷。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <string>
#define LL long long
#define DB double
using namespace std;
bool zero(DB t){return -1e-6<t&&t<1e-6;}
struct cpoint{
    DB x,y;
    void get(){scanf("%lf%lf",&x,&y);}
};
DB ra,rb,rc;
cpoint a,b,c;
DB dist(cpoint a,cpoint b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
cpoint tar[109];
DB getrand()
{
    return (rand()*rand())%1000000/1000000.0*(rand()&1?-1:1);
}
DB ma(cpoint t)
{
    return max(fabs(t.x),fabs(t.y));
}
DB bin[109];
DB getbin(cpoint t)
{
    if(dist(t,a)<ra+1e-12||dist(t,b)<rb+1e-12||dist(t,c)<rc+1e-12) return 1e20;
    DB t1 = asin(ra/dist(t,a)),t2 =asin(rb/dist(t,b)),t3 = asin(rc/dist(t,c));
    return max(max(fabs(t1-t2),fabs(t1-t3)),fabs(t2-t3));
}
void init()
{
    for(int i=0;i<100;i++)
    {
        tar[i].x = getrand()*10;
        tar[i].y = getrand()*10;
    }
    for(int i=0;i<100;i++) bin[i] = getbin(tar[i]);
}
void solve()
{
    DB T=max(max(ma(a),ma(b)),ma(c))/5,delt=0.95,EPS = 1e-9;
    init();
    for(DB t=T;t>EPS;t*=delt)
    {
        cpoint tmp;
        for(int i=0;i<100;i++)
        {
            tmp.x = tar[i].x + t*getrand();
            tmp.y = tar[i].y + t*getrand();
            DB k = getbin(tmp);
            if(k<bin[i])
            {
                bin[i] = k;
                tar[i] = tmp;
            }
        }
    }
    for(int i=0;i<100;i++) 
    if((bin[i])<1e-5)
    {
        printf("%.5lf %.5lf\n",tar[i].x+EPS,tar[i].y+EPS);
        return;
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    a.get();scanf("%lf",&ra);
    b.get();scanf("%lf",&rb);
    c.get();scanf("%lf",&rc);
    solve();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值