Codeforces Beta Round #2 C. Commentator problem 模拟退火
C. Commentator problem
题目连接:
http://www.codeforces.com/contest/2/problem/C
Description
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 ≤ x, y ≤ 103), and r (1 ≤ r ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Sample Input
0 0 10
60 0 10
30 30 10
Sample Output
30.00000 0.00000
Hint
题意
给你三个圆,现在你要找一个点,使得这个点和每个圆形成的切线的角度都是一样的。
如果有多个点,那么选择角度最大的那个点。
题解:
假设离那个圆的圆心的距离为D,那么ang = asin(D/r)这个很显然。
然后我们确保ang都相同就好了。
然后角度越大,其实就是距离越近。
然后这个东西直接退火一下就好了。
嘟嘟嘟,随便退一退。
代码
#include<bits/stdc++.h>
using namespace std;
struct node
{
double x,y;
double r;
}p[3];
double dis(double x,double y,node t)
{
return sqrt((x-t.x)*(x-t.x)+(y-t.y)*(y-t.y));
}
double cost(double x,double y)
{
double ang[3];
for(int i=0;i<3;i++)
ang[i]=dis(x,y,p[i])/p[i].r;
double d[3];
for(int i=0;i<3;i++)
d[i]=ang[i]-ang[(i+1)%3];
return d[0]*d[0]+d[1]*d[1]+d[2]*d[2];
}
int main()
{
for(int i=0;i<3;i++)
cin>>p[i].x>>p[i].y>>p[i].r;
double x=0,y=0;
for(int i=0;i<3;i++)
x+=p[i].x/3,y+=p[i].y/3;
double t=1.0;
while(t>1e-5)
{
int flag = 0;
if(cost(x+t,y)<cost(x,y))x+=t,flag=1;
else if(cost(x,y+t)<cost(x,y))y+=t,flag=1;
else if(cost(x-t,y)<cost(x,y))x-=t,flag=1;
else if(cost(x,y-t)<cost(x,y))y-=t,flag=1;
if(!flag)t*=0.5;
}
if(fabs(cost(x,y))<1e-5)printf("%.12f %.12f\n",x,y);
}
Codeforces Beta Round #2 C. Commentator problem 模拟退火的更多相关文章
- Codeforces Beta Round #2 C. Commentator problem
模拟退火果然是一个非常高端的东西,思路神马的全然搞不懂啊~ 题目大意: 给出三个圆,求一点到这三个圆的两切线的夹角相等. 解题思路: 对于这个题来说还是有多种思路的 .只是都搞不明确~~ /害羞脸 ...
- Codeforces Beta Round #17 A - Noldbach problem 暴力
A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round#2
Codeforces Beta Round#2 http://codeforces.com/contest/2 A 模拟题 #include<bits/stdc++.h> using na ...
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
随机推荐
- wait函数
当一个进程正常或异常终止时,内核就向其父进程发送SIGCHLD信号.子进程终止是一个异步事件(其能够在父进程运行的任何时候发生). 对于wait(),其调用者,即父进程可以有如下状态: 如果其所有子进 ...
- linux编程之文件操作
在linux下用文件描述符来表示设备文件盒普通文件,文件描述符是一个整型的数据,所有对文件的操作都是通过文件描述符来实现的. 文件描述符是文件系统中连接用户空间和内核空间的枢纽,当我们打开一个或者创建 ...
- [device tree] interrupt
Specifying interrupt information for devices ============================================ 1) Interru ...
- linux 下多版本gcc 共存问题
linux 下多版本gcc 共存问题 http://blog.csdn.net/isfirst/article/details/42296583 参考 http://blog.csdn.net/chi ...
- Linux 日志系统及分析
简介 在Centos 7.x / RHEL 7.x 的版本,系统日志是由一个名为 rsyslog的服务管理的,默认的日志守护进程为 rsyslog , rsyslog 是 syslog 的升级版本,默 ...
- Python初学--字符串
ASCII.Unicode和UTF-8的关系 在计算机内存中,统一使用Unicode编码,当需要保存到硬盘或者需要传输的时候,就转换为UTF-8编码 记事本编辑的时候,从文件读取的UTF-8字符被转换 ...
- php各个版本的区别
一. PHP 5.2.5.3.5.4.5.5.5.6 版本区别对比以及新功能详解 PHP5.2 以前:autoload, PDO 和 MySQLi, 类型约束 PHP5.2:JSON 支持 PHP5. ...
- Django REST Framework JWT提供的登录签发的视图
Django REST Framework JWT提供了一个视图.在我们登录的时候,会校验用户名.密码是否正确.如果信息无误,可以返回一个JWT token.就可以简单地实现了记录用户登录状态. 用法 ...
- ZOJ-2753
Min Cut (Destroy Trade Net) Time Limit: 15 Seconds Memory Limit: 32768 KB Given an undirected g ...
- LeetCode解题报告—— 2 Keys Keyboard & Longest Palindromic Substring & ZigZag Conversion
1. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You ...