let's start Code

1118 - Incredible Molecules

Problem link: 1118 - Incredible Molecules

Topic: Geometry

Resources:

Robert Eisele

Matrix.Code

Code:

#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
const int N = 11;
struct PT
{
int x, y;
PT(int x, int y): x(x), y(y) {}
};
int sqr(int a) {return a * a;}
int dist(PT a, PT b)
{
return sqr(a.x - b.x) + sqr(a.y - b.y);
}
int main()
{
//FASTIO
///*
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
//*/
int T;
//scanf("%d", &T);
T = 1;
cin >> T;
for (int cs = 1; cs <= T; cs++) {
int x1, y1, r1;
int x2, y2, r2;
cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
if (r1 < r2) {
swap(x1, x2);
swap(y1, y2);
swap(r1, r2);
}
double d = sqrt(dist(PT(x1, y1), PT(x2, y2)));
if (r1 + r2 <= d)printf("Case %d: 0\n", cs);
else if (r1 + r2 >= d && fabs(r1 - r2) < d) {
double ang1 = acos((r1 * r1 + d * d - r2 * r2) / (2 * r1 * d));
double ang2 = acos((r2 * r2 + d * d - r1 * r1) / (2 * r2 * d));
double area = .5 * r1 * r1 * (2 * ang1) - .5 * r1 * r1 * sin(2 * ang1) + .5 * r2 * r2 * (2 * ang2) - .5 * r2 * r2 * sin(2 * ang2);
printf("Case %d: %.9lf\n", cs, area);
}
else {
double r = min(r1, r2);
printf("Case %d: %.9lf\n", cs, PI * r * r);
}
}
return 0;
}
view raw 1118.cpp hosted with ❤ by GitHub

Share:

Related Posts:

No comments:

Post a Comment

About

let's start CODE

Popular Posts