Gym - 102021B Battle Royale 【数学】


传送门:Gym - 102021B



Battle Royale games are the current trend in video games and Gamers Concealed Punching
Circles (GCPC) is the most popular game of them all. The game takes place in an area that, for
the sake of simplicity, can be thought of as a two-dimensional plane. Movement and positioning
are a substantial part of the gameplay, but getting to a desired location can be dangerous. You
are confident in your ability to handle the other players, however, while you are walking to your
destination, there are two hazards posed by the game itself:

  • The game zone is bounded by a blue circle. Outside of this circle, there is a deadly force
    field that would instantly take you out of the game.
  • Inside the game zone, there is a red circle where you are exposed to artillery strikes. This
    circle is also too risky to enter.

You want to move from one spot on the map to another, but the direct path to your destination is
blocked by the red circle, so you need to find a way around it. Can you find the shortest path that
avoids all hazards by never leaving the blue or entering the red circle? Touching the boundaries
of the circles is fine, as long as you do not cross them.

Input
The input consists of:

  • one line with two integers xc, yc specifying your current location;
  • one line with two integers xd, yd specifying your destination;
  • one line with three integers xb, yb, rb specifying the center and radius of the blue circle;
  • one line with three integers xr, yr, rr specifying the center and radius of the red circle.
    All coordinates have an absolute value of at most 1 000, and 1 ≤ rb, rr ≤ 1 000. The red circle
    is strictly inside the blue circle. Your current location and destination are strictly inside the blue
    circle and strictly outside of the red circle, and the direct path between them is blocked by the
    red circle.

Output
Output the length of the shortest path that does not leave the blue or enter the red circle. The
output must be accurate up to a relative or absolute error (whichever is lower) of 10−7

Sample Input 1
0 0
10 0
0 0 1000
5 0 2
.
Sample Output 1
10.8112187742



题意:
平面内有一个大圆,大圆里面有两个点(我假设C和D)和一个小圆。你不能穿过小圆的区域,也不能走出大圆,问从C到D的最短距离。


题解:
如果线段CD没有穿过小圆,那么最小距离就是CD的距离,所有我们要讨论的就是如果CD穿过小圆,我们怎么求最短距离。

在这里插入图片描述
应该过C,D两点做小圆的切线,l1为切点到C的距离,l2为切点到D的距离,l3为在小圆上两切点的弧长。
那么最小距离就应该是 l 1 + l 2 + l 3 l1+l2+l3 l1+l2+l3
计算弧长时,有弧长公式: S = a ∗ r S=a*r S=ar 。( a a a为扇形的角度(弧度制), r r r为扇形半径)
计算角度可以用 a c o s ( ) acos() acos() 这个函数(即arccos),该函数返回的就是弧度。

一开始我认为最小距离应该是CD的长度减去穿过圆的部分,加上圆弧的长度,但是由两点之间直线最短我们可以得到:由C,D点到切点的距离更小, l 3 l3 l3 的长度的一样的。(可以结合上面的图)



AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
struct Node
{
  int x,y;
};
double getd(Node a,Node b,Node c)//计算点到直线距离,a,b为直线上两点,c为直线外的点
{
  double d=(fabs((b.y-a.y)*c.x+(a.x-b.x)*c.y+((b.x*a.y)-(a.x*b.y))))/(sqrt(pow(b.y-a.y,2)+pow(a.x-b.x,2)));
  return d;
}
double getl(Node a,Node b)
{
  double d=sqrt(pow(b.x-a.x,2)+pow(b.y-a.y,2));
  return d;
}
int main()
{
  Node c,d,b,r;
  int rr,rb;
  scanf("%d%d",&c.x,&c.y);
  scanf("%d%d",&d.x,&d.y);
  scanf("%d%d%d",&b.x,&b.y,&rb);
  scanf("%d%d%d",&r.x,&r.y,&rr);
  double D=getd(c,d,r);
  if(D>=rr)
  {
    double len=sqrt(pow(d.x-c.x,2)+pow(d.y-c.y,2));
    printf("%.10lf\n",len);
  }
  else
  {
    double x1=getl(c,r),x2=getl(d,r);
    double l1=sqrt(x1*x1-rr*rr),l2=sqrt(x2*x2-rr*rr);
    double a=acos(D/x1)+acos(D/x2)-acos(rr*1.0/x1)-acos(rr*1.0/x2);
    double l3=a*rr;
    double l=l1+l2+l3;  
    printf("%.10lf\n",l);
  }
  return 0;
}

2D Tools v1.6 3D Games Magic Pack Vol 1 v1.4 3D Tower Defense Kit v1.7 3D-Cloud Models 6000Flat2.2 Abandoned Factory Scene 1.8 Abandoned Railway Station v.1.0.1 Advanced First Person Controller - AFPC 1.0 AdvancedHarvesting AdvancedKyMagicFX01 v1.1 Adventure Creator 1.65.2 Alpha Mask UI Sprites Quads v2.1 Amplify Shader Editor Andro id Etcetera Plugin v3.9 Android In App Billing Plugin v2.15 Android Social Networking v2.21 Angelic Sword Set v1.0 Animal pack deluxe Aoi Character Pack v1.11 AQUAS WaterRiver Set Auto tile available Nostalgia 2 v2.1.6 Battle Skill FX v1.2 Beat Em Up Template 3D Update 1.3 Bio IK BlockMonsterPack Bolt Buff Damage Fx Pack v1.0 Car Game Complete Templete Cartoon Style Fantasy Environment Pack 1.0 Cascade - River Lake Waterfall and more v1.2.0 Channel Packer Character Respawn FX v1.1 Chronos v2.4.14 Cinema Pro Cams - Film Lens 3D Toolkit v1.4.3.2 CLog Logger Flexible logging framework Colorbleed Combat Magic VFX Vol1 v1.3 Comic CarToon outline v1.0 Complete_Physics_Platformer_Kit Cube World 1.0 Custom Slots framework v1.4 Dark Ages Dungeon II v1.15 Dark Mage Game Character Sprites Darts Starter Kit DCG Toon Shaders v1.1 Destructible Cars 3 - VAN 2 1.0 DoozyUI Complete UI Management System v2.9.1 Dungeon Architect 1.8.0 (1) Dungeon Architect 1.8.0 Dungeon Architect v1.7.0 Dynamic Fog Mist v6.5 Dynamic Starry Sky v1.5 Easy Main Menu 1.0f Easy Map - system v1.53 Easy Mobile Pro v2.0.0 EnhancedScroller v2.15.6 Explosive Realistic VFX Texture Pack v1 Extreme FX Vol1 v2.1 Factory District Fantasy Horde - Barbarians v1.03 Fantasy Horde - Dwarfs Fantasy Horde - Goblin Fantasy Horde - Knights Fantasy Horde - Skeletons Fantasy Horde - Trolls (webrip) Fantasy Horde - Villagers Fantasy Horde - Zombie FERNS World Filmic Tonemapping DELUXE v2.0.2 Final Camera Effects Pro Flash Effects Vol1 v4.6.6.f2 FPS pick up item pack Gaia.1.8.0 Galactic Adventure Music Pack 1 v2.0 Game Effect v01.2 GameFlow Half-Price Integrate FX v1.0.2 Haunted Town v1.3 HEROIC FANT
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值