hdoj:2080

夾角有多大II

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10656    Accepted Submission(s): 5510



Problem Description
此次xhd面臨的問題是這樣的:在一個平面內有兩個點,求兩個點分別和原點的連線的夾角的大小。

注:夾角的範圍[0,180],兩個點不會在圓心出現。

 

Input
輸入數據的第一行是一個數據T,表示有T組數據。
每組數據有四個實數x1,y1,x2,y2分別表示兩個點的座標,這些實數的範圍是[-10000,10000]。

 

Output
對於每組輸入數據,輸出夾角的大小精確到小數點後兩位。
 

Sample Input
  
  
  
  
2 1 1 2 2 1 1 1 0
 

Sample Output
  
  
  
  
0.00 45.00

 

#include <iostream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <cmath>
#define PI 3.141592653
using namespace std;

int main()
{
    int T;
    double x1, y1, x2, y2;
    double a,b,cosx, arcosx;
    cin >> T;
    while (T--)
    {
        cin >> x1 >> y1 >> x2 >> y2;
        a = x1*x2 + y1*y2;
        b = sqrt((x1*x1 + y1*y1)*(x2*x2 + y2*y2));
        cosx = a / b;
        arcosx = acos(cosx) /PI *180;
        printf("%.2lf\n", arcosx);
    }
    return 0;
}
本站公眾號
   歡迎關注本站公眾號,獲取更多信息