#include #include #include using namespace std; bool check_inside(const double &x, const double &y, const int &a) { //查看有沒有在斜線區域的方式就是確認其與四個端點的距離是不是都在 a 之內 if(sqrt(x * x + y * y) > a) return false; if(sqrt(x * x + (a-y) * (a-y)) > a) return false; if(sqrt((a-x) * (a-x) + y * y) > a) return false; if(sqrt((a-x) * (a-x) + (a-y) * (a-y)) > a) return false; return true; } int main() { int N, a; // N : 下面要再讀幾筆資料, a : 正方型邊長 while(cin >> N >> a) { if(!N) break; double x, y; // 點的 X 和 Y 值 int inside_count = 0; for(int i=0;i> x >> y; if(check_inside(x, y, a)) ++inside_count; } double ratio = (double)inside_count / (double)N; cout << fixed << setprecision(5) << double(ratio * a * a * 100000) / 100000<< endl; } return 0; }
文章標籤
全站熱搜
創作者介紹
創作者 eric30 的頭像
eric30

*Our Blog*

eric30 發表在 痞客邦 留言(0) 人氣(0)