本文主要是介绍hdu 6354 E. Everything Has Changed,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:点击打开链接
题意: 给你一个原点在(0,0),半径为R的圆盘以及m个小圆。第i个小圆的原点在(xi,yi),半径为ri。每个小圆可能会与大圆盘相交,现在问你m个小圆将大圆覆盖后的周长并。(题目保证小圆不会相交,且小圆不会完全把大圆覆盖)
分析:余弦定理,大大简化运算。
代码:
#pragma comment(linker, "/STACK:102400000,102400000")
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<string>
#include<cstdio>
#include<bitset>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
using namespace std;
#define debug test
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
typedef pair<int,int> PII;
const ll mod = 1e9+7;
const int N = 1e6+10;ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qp(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int to[4][2]={{-1,0},{1,0},{0,-1},{0,1}};int t;int main() {ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);scanf("%d", &t);while(t--) {int n, R;scanf("%d%d", &n, &R);double ans = 0, rem = PI;for(int i = 1; i <= n; ++i) {int x, y, r;scanf("%d%d%d", &x, &y, &r);int dis2 = x * x + y * y;if(dis2 < (R - r) * (R - r) || dis2 > (R + r) * (R + r))continue;double dis = sqrtl(dis2);double ang1 = acos((dis2 + R * R - r * r) / (2 * R * dis));double ang2 = acos((dis2 - R * R + r * r) / (2 * r * dis));rem -= ang1;ans += 2 * r * ang2;}ans += 2 * R * rem;printf("%.20f\n", ans);}return 0;
}
这篇关于hdu 6354 E. Everything Has Changed的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!