1、UESTC 994 两个圆的公共面积
解题思路:
两个相交圆的公共面积为两个扇形的面积之和减去菱形的面积
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
const double PI = acos(-1);
double dis(double x1, double y1, double x2, double y2);
int main()
{
#ifdef __AiR_H
freopen("in.txt", "r", stdin);
#endif // __AiR_H
int T;
scanf("%d", &T);
while (T--) {
double x1, y1, r1, x2, y2, r2;
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &r1, &x2, &y2, &r2);
double dis_r = dis(x1, y1, x2, y2);
if (r2 > r1) {
swap(r2, r1); swap(x1, x2); swap(y1, y2);
}
double common_s = 0.0;
double difference_r = r1 -r2, sum_r = r1 + r2;
if (dis_r <= difference_r) {
common_s = r2 * r2 * PI;
} else if (dis_r < sum_r) {
double angle_r2 = acos((r1*r1 + dis_r*dis_r - r2*r2) / (2*r1*dis_r)); //r2对应的角
double angle_r1 = acos((r2*r2 + dis_r*dis_r - r1*r1) / (2*r2*dis_r)); //r1对应的角
double rctangle_s = r1 * sin(angle_r2) * dis_r;
double s1 = angle_r2 * r1 * r1;
double s2 = angle_r1 * r2 * r2;
common_s = s1 + s2 - rctangle_s;
}
printf("%.2f\n", common_s);
}
return 0;
}
double dis(double x1, double y1, double x2, double y2)
{
return sqrt((x2-x1) * (x2 - x1) + (y2-y1) * (y2-y1));
}
2、USETC 93 King's Sanctuary
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
int x[10], y[10];
bool IsParallelogram(void);
bool IsRectangle(void);
bool IsDiamond(void);
int main()
{
#ifdef __AiR_H
freopen("in.txt", "r", stdin);
#endif // __AiR_H
int T;
scanf("%d", &T);
int Case = 0;
while (T--) {
printf("Case #%d: ", ++Case);
for (int i = 1; i <= 4; ++i) {
scanf("%d%d", &x[i], &y[i]);
}
if (!IsParallelogram()) {
printf("Others\n");
} else {
bool flag1 = IsRectangle(), flag2 = IsDiamond();
if (flag1 && flag2) {
printf("Square\n");
} else if (flag1) {
printf("Rectangle\n");
} else if (flag2) {
printf("Diamond\n");
} else {
printf("Parallelogram\n");
}
}
}
return 0;
}
bool IsParallelogram(void) //利用平行四边形对边相等的性质
{
int a, b, c, d;
a = (x[2] - x[1]) * (x[2] - x[1]) + (y[2] - y[1]) * (y[2] - y[1]);
b = (x[4] - x[3]) * (x[4] - x[3]) + (y[4] - y[3]) * (y[4] - y[3]);
c = (x[3] - x[2]) * (x[3] - x[2]) + (y[3] - y[2]) * (y[3] - y[2]);
d = (x[4] - x[1]) * (x[4] - x[1]) + (y[4] - y[1]) * (y[4] - y[1]);
if (a == b && c == d) {
return true;
}
return false;
}
bool IsRectangle(void) //利用矩形对角线相等的性质
{
int a, b;
a = (x[3]-x[1])*(x[3]-x[1])+(y[3]-y[1])*(y[3]-y[1]);
b = (x[4]-x[2])*(x[4]-x[2])+(y[4]-y[2])*(y[4]-y[2]);
if (a == b) {
return true;
}
return false;
}
bool IsDiamond(void) //利用菱形对角线垂直的性质
{
return ((x[3] - x[1]) * (x[4] - x[2]) + (y[3] - y[1]) * (y[4] - y[2])) == 0 ? true : false;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
int x[10], y[10];
bool IsParallelogram(void);
bool IsRectangle(void);
bool IsDiamond(void);
int main()
{
#ifdef __AiR_H
freopen("in.txt", "r", stdin);
#endif // __AiR_H
int T;
scanf("%d", &T);
int Case = 0;
while (T--) {
printf("Case #%d: ", ++Case);
for (int i = 1; i <= 4; ++i) {
scanf("%d%d", &x[i], &y[i]);
}
if (!IsParallelogram()) {
printf("Others\n");
} else {
bool flag1 = IsRectangle(), flag2 = IsDiamond();
if (flag1 && flag2) {
printf("Square\n");
} else if (flag1) {
printf("Rectangle\n");
} else if (flag2) {
printf("Diamond\n");
} else {
printf("Parallelogram\n");
}
}
}
return 0;
}
bool IsParallelogram(void) //利用平行四边形对边相等的性质
{
int a, b, c, d;
a = (x[2] - x[1]) * (x[2] - x[1]) + (y[2] - y[1]) * (y[2] - y[1]);
b = (x[4] - x[3]) * (x[4] - x[3]) + (y[4] - y[3]) * (y[4] - y[3]);
c = (x[3] - x[2]) * (x[3] - x[2]) + (y[3] - y[2]) * (y[3] - y[2]);
d = (x[4] - x[1]) * (x[4] - x[1]) + (y[4] - y[1]) * (y[4] - y[1]);
if (a == b && c == d) {
return true;
}
return false;
}
bool IsRectangle(void) //利用矩形对角线相等的性质
{
int a, b;
a = (x[3]-x[1])*(x[3]-x[1])+(y[3]-y[1])*(y[3]-y[1]);
b = (x[4]-x[2])*(x[4]-x[2])+(y[4]-y[2])*(y[4]-y[2]);
if (a == b) {
return true;
}
return false;
}
bool IsDiamond(void) //利用菱形对角线垂直的性质
{
return ((x[3] - x[1]) * (x[4] - x[2]) + (y[3] - y[1]) * (y[4] - y[2])) == 0 ? true : false;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <cctype>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
const ull mod = 1e9 + 7;
const int INF = 0x7fffffff;
int x[10], y[10];
bool IsParallelogram(void);
bool IsRectangle(void);
bool IsDiamond(void);
int main()
{
#ifdef __AiR_H
freopen("in.txt", "r", stdin);
#endif // __AiR_H
int T;
scanf("%d", &T);
int Case = 0;
while (T--) {
printf("Case #%d: ", ++Case);
for (int i = 1; i <= 4; ++i) {
scanf("%d%d", &x[i], &y[i]);
}
if (!IsParallelogram()) {
printf("Others\n");
} else {
bool flag1 = IsRectangle(), flag2 = IsDiamond();
if (flag1 && flag2) {
printf("Square\n");
} else if (flag1) {
printf("Rectangle\n");
} else if (flag2) {
printf("Diamond\n");
} else {
printf("Parallelogram\n");
}
}
}
return 0;
}
bool IsParallelogram(void)
{
int a, b, c, d;
a = (x[2] - x[1]) * (y[4] - y[3]);
b = (x[4] - x[3]) * (y[2] - y[1]);
c = (x[3] - x[2]) * (y[4] - y[1]);
d = (x[4] - x[1]) * (y[3] - y[2]);
if (a == b && c == d) {
return true;
}
return false;
}
bool IsRectangle(void) //利用矩形对角线相等的性质
{
int a, b;
a = (x[3]-x[1])*(x[3]-x[1])+(y[3]-y[1])*(y[3]-y[1]);
b = (x[4]-x[2])*(x[4]-x[2])+(y[4]-y[2])*(y[4]-y[2]);
if (a == b) {
return true;
}
return false;
}
bool IsDiamond(void) //利用菱形对角线垂直的性质
{
return ((x[3] - x[1]) * (x[4] - x[2]) + (y[3] - y[1]) * (y[4] - y[2])) == 0 ? true : false;
}