HDU 6219

/*最大凸包*/
#include #include <string.h> #include using namespace std; const int maxsz = 55; int m, dp[maxsz][maxsz], ans; struct Point { int x, y; Point ( int xx = 0, int yy = 0 ) : x(xx), y(yy){}; Point operator + (const Point p ) { return Point ( x + p.x, y + p.y ) ; } Point operator - (const Point p ) { return Point ( x - p.x, y - p.y ) ; } }point[maxsz], t[maxsz]; int Dot ( Point i, Point j ) { return i.x * j.x + i.y * j.y; } int Cross ( Point i, Point j ) { return i.x * j.y - i.y * j.x; } bool cmp1 ( const Point &i, const Point &j ) { return i.y == j.y ? i.x < j.x : i.y < j.y; } bool cmp2 ( const Point &i, const Point &j ) { return Cross (i, j) == 0 ? Dot (i, i) < Dot (j, j) : Cross (i, j) > 0; } void solve () { for (int i = 0; i <= m; i++) { for (int j = i; j <= m; j++) dp[i][j] = dp[j][i] = 0; } for (int i = 2; i <= m; i++) { for (int j = 1; j < i; j++) { if (Cross(t[i], t[j]) == 0) continue; bool emp = 1;// in triangle for (int k = j + 1; k < i; k++) { if (Cross(t[k], t[i]) > 0 && Cross (t[j], t[k]) > 0 && Cross (t[i] - t[j], t[k] - t[j]) > 0) emp = 0; } if (!emp) continue; int area = Cross (t[j], t[i]); dp[i][j] = area; if (Cross(t[j], t[j-1])) {//共线 for (int k = 1; k < j; k++) { if (Cross(t[k] - t[i], t[j] - t[i]) > 0) dp[i][j] = max(dp[i][j], dp[j][k] + area); } } ans = max(ans, dp[i][j]); } } } int main () { int T, n; scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &point[i].x, &point[i].y); sort ( point + 1, point + 1 + n, cmp1);// sort LTL ans = 0; for (int i = 1; i <= n-2; i++, m = 0) { for (int j = i + 1; j <= n; j++) t[++m] = point[j] - point[i]; sort ( t + 1, t + 1 + m, cmp2);// sort angle solve(); } printf("%.1lf\n", 1.0 * ans / 2); } return 0; }

 

你可能感兴趣的:(HDU 6219)