[TIOJ] 1115. 夕陽問題

題目連結:http://tioj.infor.org/problems/1115
計算幾何題OAO,我三角函數有點爛ww,不過大概就是y>0時,就是算整個原扣掉在下面那塊,也就是扇形減三角形,而y<0時,就只要算上面那塊,也就是扇形減三角形
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	double x,y,r,ans;
	while(cin>>x>>y>>r){
		double theta = acos(abs(y/r))*2;
		if(y>=r)
			ans=r*r*PI;
		else if(y<=-r)
			ans=0;
		else if(y<=0)
			ans = r*r*theta/2. - r*r*sin(theta)/2.;
		else
			ans = r*r*PI - r*r*theta/2. + r*r*sin(theta)/2.;
		cout<<fixed<<setprecision(2)<<ans<<'\n';
	}
	return 0;
}

留言

這個網誌中的熱門文章

[TIOJ] 1902. 「殿仁.王,不認識,誰啊?」,然後他就死了……

[AtCoder] [經典競程 90 題] 024 - Select +/- One(★2)

[AtCoder] [經典競程 90 題] 022 - Cubic Cake(★2)