SRV431 DIV1 250
There is a laser cannon at coordinates (0, 0) on the cartesian plane. There are also several targets on the plane. Each target is a vertical line segment, and the endpoints of the i-th target are at coordinates (x[i], y1[i]) and (x[i], y2[i]). A random angle between -Pi/2 and Pi/2, inclusive, is chosen, and a single shot is fired. The angle -Pi/2 is straight down vertically, 0 is straight to the right horizontally, and Pi/2 is straight up vertically. A shot is a straight ray of infinite length starting from the point (0, 0). A shot hits a target if there is a common point between them. Return the expected number of targets that will be hit by the single shot. Hitting a target doesn't change the direction of the laser shot.
ーPI/2からPI/2の範囲でランダムにレーザーを撃つときの飛行機に当たる確立。んー
#include <stdio.h> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; class LaserShooting { public: double numberOfHits(vector<int> x, vector<int> y1, vector<int> y2) { int i; double sum = 0,r1,r2; for(i=0;i<x.size();i++) { r1 = atan((double)y1[i]/(double)x[i]); r2 = atan((double)y2[i]/(double)x[i]); sum += abs(r1 - r2); } return sum/M_PI; }
三角形の角度をatan(高さ/底辺)で求めて全部足して(PT/2-(-PI/2))で割れば良いのかな