lightoj-1433 - Minimum Arc Distance(几何)

1433 - Minimum Arc Distance
PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB
You all probably know how to calculate the distance between two points in two dimensional cartesian plane. But in this problem you have to find the minimum arc distance between two points and they are on a circle centered at another point.

You will be given the co-ordinates of the points A and B and co-ordinate of the center O. You just have to calculate the minimum arc distance between A and B. In the picture, you have to calculate the length of arc ACB. You can assume that A and B will always be on the circle centered at O.

Input
Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing six integers Ox, Oy, Ax, Ay, Bx, By where (Ox, Oy) indicates the co-ordinate of O, (Ax, Ay) denote the co-ordinate of A and (Bx, By) denote the co-ordinate of B. All the integers will lie in the range [1, 10000].

Output
For each case, print the case number and the minimum arc distance. Errors less than 10-3 will be ignored.

Sample Input
Output for Sample Input
5
5711 3044 477 2186 3257 7746
3233 31 3336 1489 1775 134
453 4480 1137 6678 2395 5716
8757 2995 4807 8660 2294 5429
4439 4272 1366 8741 6820 9145
Case 1: 6641.81699183
Case 2: 2295.92880
Case 3: 1616.690325
Case 4: 4155.64159340
Case 5: 5732.01250253

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double pi = 3.1415926535898;
double dist(double x1,double y1,double x2,double y2){
    return sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}

int main(){

    int T;
    double ox,oy,ax,ay,bx,by,a,b,c,arc;

    scanf("%d",&T);
    for(int t=1;t<=T;t++){

        scanf("%lf%lf%lf%lf%lf%lf",&ox,&oy,&ax,&ay,&bx,&by);

        a = dist(ox,oy,ax,ay);
        c = dist(ax,ay,bx,by);
        arc = acos((a*a*2-c*c)/(2*a*a));
        printf("Case %d: %.3lf\n",t,a*arc);

    }

    return 0;
} 
时间: 2024-11-26 01:35:52

lightoj-1433 - Minimum Arc Distance(几何)的相关文章

最小编辑距离(Minimum edit distance)

最小编辑距离是计算欧式距离的一种方法,可以被用于计算文本的相似性以及用于文本纠错,因为这个概念是俄罗斯科学家 Vladimir Levenshtein 在1965年提出来的,所以编辑距离又称为Levenshtein距离. 简单的理解就是将一个字符串转换到另一个字符串所需要的代价(cost),付出的代价越少表示两个字符串越相似,编辑距离越小,从一个字符串转换到另一个字符串简单的归纳可以有以下几种操作,1.删除(delete)2.插入(insert)3.修改(update),其中删除和插入的代价可以

Minimum edit distance(levenshtein distance)(最小编辑距离)初探

最小编辑距离的定义:编辑距离(Edit Distance),又称Levenshtein距离,是指两个字串之间,由一个转成另一个所需的最少编辑操作次数.许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符. 例如将kitten一字转成sitting: sitten(k→s) sittin(e→i) sitting(→g) 俄罗斯科学家Vladimir Levenshtein在1965年提出这个概念. Thewords `computer' and `commuter' are

Minimum Edit Distance with Dynamic Programming

1. Question / 实践题目 2. Analysis / 问题描述 3. Algorithm / 算法描述 3.1. Substitution 3.2. Insertion 3.3. Deletion 3.4. Sepcial Cases 3.5. Equation 4. Fill the table / 填表 4.1. Dimention 4.2. Range 4.3. Order 4.4. Related Code 5. Show Me the Code / 完整代码 6. T(n)

lightoj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

light oj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

【leetcode】1320. Minimum Distance to Type a Word Using Two Fingers

题目如下: You have a keyboard layout as shown above in the XY plane, where each English uppercase letter is located at some coordinate, for example, the letter A is located at coordinate (0,0), the letter B is located at coordinate (0,1), the letter P is

HDU 4712 Hamming Distance (随机函数)

Hamming Distance Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1806    Accepted Submission(s): 714 Problem Description (From wikipedia) For binary strings a and b the Hamming distance is equal

(每日算法)Leetcode--Edit Distance(编辑距离)

简单地说,就是仅通过插入(insert).删除(delete)和替换(substitute)个操作将一个字符串s1变换到另一个字符串s2的最少步骤数.熟悉算法的同学很容易知道这是个动态规划问题. 其实一个替换操作可以相当于一个delete+一个insert,所以我们将权值定义如下: I  (insert):1 D (delete):1 S (substitute):1 示例: intention->execution Minimal edit distance: delete i ; n->e

Edit Distance (or Levenshtein Distance) python solution for leetcode EPI 17.2

https://oj.leetcode.com/problems/edit-distance/ Edit Distance  Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted