// C++Exercise.cpp : 定义控制台应用程序的入口点。
//
#include<iostream>
#include<string>
#include<stack>
#include<map>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstdio>
#define eps 1e-9
using namespace std;
int n;
typedef struct{
double x, y;
}point;
bool Intersect(vector<point>& vp,int i,int j){
point A = vp[i];
point B = vp[i + 1];
point C = vp[j];
point D = vp[j+1];
if (min(A.x, B.x) > max(C.x, D.x) || min(A.y, B.y) > max(C.y, D.y)
|| min(C.x, D.x) > max(A.x, B.x) || min(C.y, D.y) > max(A.y, B.y)) return false;
double a = (C.y - A.y)*(B.x - A.x) - (C.x - A.x)*(B.y - A.y);
double b = (D.y - A.y)*(B.x - A.x) - (D.x - A.x)*(B.y - A.y);
double c = (C.x - D.x)*(A.y - D.y) - (C.y - D.y)*(A.x - D.x);
double d = (C.x - D.x)*(B.y - D.y) - (C.y - D.y)*(B.x - D.x);
return a*b <=eps&& c*d <=eps;
}
double Cross(point a,point b){
return a.x*b.y - a.y*b.x;
}
double Cal(vector<point>& vp){
double sum = 0;
for (int i = 0; i < vp.size(); i++){
sum += Cross(vp[i],vp[(i+1)%vp.size()]);
}
return fabs(sum)/2;
}
bool judge(double x){
if (fabs(x) < eps) return 0;
else return 1;
}
int main(){
int Figure = 0;
while (cin >> n){
if (n == 0) break;
Figure++;
vector<point> vp;
for (int i = 0; i < n; i++){
point temp;
cin >> temp.x >> temp.y;
vp.push_back(temp);
}
bool flag = true;
for (int i = 0; i < vp.size() && flag; i++){
for (int j = i + 2; j+1 < vp.size() && flag; j++){
if (Intersect(vp, i, j)) flag = false;
}
}
if (Figure > 1) cout << endl;
cout << "Figure " << Figure << ": ";
if (!flag){
cout << "Impossible" << endl;
continue;
}
double area = Cal(vp);
if (judge(area) == 0) cout << "Impossible" << endl;
else printf("%.2f\n", area);
}
return 0;
}
ZOJ 1010
最新推荐文章于 2021-07-12 14:57:00 发布