pku 1687(求面积最大的多边形的编号)

/*

*  题目要求:求面积最大的那个面的编号

*  方法:分别求每个面的面积,并比较最大的面积 

*/

#include <cmath>

#include <cstdio>

#include <cstdlib>

#include <iostream>



using namespace std;



const int N = 55;



struct point {

    int x;

    int y;

}p[N], sp[N];



double crossProd(point A, point B, point C) {

    return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x);

}



int main() {

    int t;

    scanf ("%d", &t);

    while (t--) {

        int n;

        scanf ("%d", &n);

        for (int i=1; i<=n; ++i) scanf ("%d%d", &p[i].x, &p[i].y);

        int m;

        scanf ("%d", &m);

        double maxArea = 0;

        int ans = 0;

        for (int j=1; j<=m; ++j) {

            int cs, num;

            scanf ("%d", &cs);

            int k = 0;

            for (int i=0; i<cs; ++i) {

                scanf ("%d", &num);

                sp[k++] = p[num];

            }

            double area = 0;

            for (int i=2; i<k; ++i) area += crossProd(sp[0], sp[i-1], sp[i]);

            if (maxArea < fabs(area)) {

                maxArea = fabs(area);

                ans = j;

            }

        }

        printf ("%d\n", ans);

    }

}

 

你可能感兴趣的:(pku)