Problem link: 1178 - Trapezium
Explanation: math-only-math.com
Code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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;
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;
for (int cs = 1; cs <= T; cs++) {
double a, b, c, d;
scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
double x = fabs(a - c);
double s = 0.5 * (x + b + d);
//dbg(s);
double triangle_area = sqrt(s * (s - x) * (s - b) * (s - d));
//dbg(triangle_area);
double h = (triangle_area * 2.0) / x;
//dbg(h);
double ans = 0.5 * (a + c) * h;
printf("Case %d: %.8lf\n", cs, ans);
}
return 0;
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
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; | |
for (int cs = 1; cs <= T; cs++) { | |
double a, b, c, d; | |
scanf("%lf %lf %lf %lf", &a, &b, &c, &d); | |
double x = fabs(a - c); | |
double s = 0.5 * (x + b + d); | |
//dbg(s); | |
double triangle_area = sqrt(s * (s - x) * (s - b) * (s - d)); | |
//dbg(triangle_area); | |
double h = (triangle_area * 2.0) / x; | |
//dbg(h); | |
double ans = 0.5 * (a + c) * h; | |
printf("Case %d: %.8lf\n", cs, ans); | |
} | |
return 0; | |
} |
No comments:
Post a Comment