Codeforces Beta Round #2 C. Commentator problem

來源:互聯網
上載者:User

標籤:codeforces   刷題   


類比退火果然是一個很高端的東西,思路神馬的完全搞不懂啊~


題目大意:

給出三個圓,求一點到這三個圓的兩切線的夾角相等。



解題思路:


對於這個題來說還是有多種思路的 ,不過都搞不明白~~   /害羞臉

用類比退火來解也是一件賭人品的事,因為退火的過程設計的不合理,WA妥妥的。

其實我也是學了一點點,還不是太明白啊~~



下面是代碼:

#include <set>#include <map>#include <queue>#include <math.h>#include <vector>#include <string>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <cctype>#include <algorithm>#define eps 1e-6#define pi acos(-1.0)#define inf 107374182#define inf64 1152921504606846976#define lc l,m,tr<<1#define rc m + 1,r,tr<<1|1#define zero(a) fabs(a)<eps#define iabs(x)  ((x) > 0 ? (x) : -(x))#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))#define clearall(A, X) memset(A, X, sizeof(A))#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))#define memcopyall(A, X) memcpy(A , X ,sizeof(X))#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )#define min( x, y )  ( ((x) < (y)) ? (x) : (y) )using namespace std;int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};struct circle{    double x,y,r;}cir[3];double dis(double x,double y,double xx,double yy){    return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));}double f(double x,double y){    double tmp[3];    for(int i=0;i<3;i++)        tmp[i]=dis(x,y,cir[i].x,cir[i].y)/cir[i].r; //視角一半的sin值    double ans=0;    for(int i=0;i<3;i++)        ans+=(tmp[i]-tmp[(i+1)%3])*(tmp[i]-tmp[(i+1)%3]);    return ans;}int main(){    double x=0,y=0;    for(int i=0;i<3;i++)    {        scanf("%lf%lf%lf",&cir[i].x,&cir[i].y,&cir[i].r);        x+=cir[i].x/3;        y+=cir[i].y/3;    }    double step=2;    while(step>eps)    {        double tmp=f(x,y);        int tag=-1;        for(int i=0;i<4;i++)        {            double cnt=f(x+dir[i][0]*step,y+dir[i][1]*step);            if(cnt<tmp)            {                tmp=cnt;                tag=i;            }        }        if(tag==-1)            step/=2;        else        {            x=x+dir[tag][0]*step;            y=y+dir[tag][1]*step;        }    }    if(f(x,y)<eps)        printf("%.5lf %.5lf\n",x,y);    return 0;}


Codeforces Beta Round #2 C. Commentator problem

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.