1. 程式人生 > >Codeforces Beta Round #2 C. Commentator problem

Codeforces Beta Round #2 C. Commentator problem

ng- mco sca snippet [1] div fine ostream codeforce


模擬退火果然是一個非常高端的東西,思路神馬的全然搞不懂啊~


題目大意:

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



解題思路:


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

用模擬退火來解也是一件賭人品的事。由於退火的過程設計的不合理,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