18.12.17 POJ 1569 Myacm Triangles

Posted yalphait

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了18.12.17 POJ 1569 Myacm Triangles相关的知识,希望对你有一定的参考价值。

描述

技术分享图片


There has been considerable archeological work on the ancient Myacm culture. Many artifacts have been found in what have been called power fields: a fairly small area, less than 100 meters square where there are from four to fifteen tall monuments with crystals on top. Such an area is mapped out above. Most of the artifacts discovered have come from inside a triangular area between just three of the monuments, now called the power triangle. After considerable analysis archeologists agree how this triangle is selected from all the triangles with three monuments as vertices: it is the triangle with the largest possible area that does not contain any other monuments inside the triangle or on an edge of the triangle. Each field contains only one such triangle. 

Archeological teams are continuing to find more power fields. They would like to automate the task of locating the power triangles in power fields. Write a program that takes the positions of the monuments in any number of power fields as input and determines the power triangle for each power field.

A useful formula: the area of a triangle with vertices (x1, y1), (x2, y2), and (x3, y3) is the absolute value of

0.5 * [(y3 - y1)(x2 - x1) - (y2 - y1)(x3 - x1)]. 
输入For each power field there are several lines of data. The first line is the number of monuments: at least 4, and at most 15. For each monument there is a data line that starts with a one character label for the monument and is followed by the coordinates of the monument, which are nonnegative integers less than 100. The first label is A, and the next is B, and so on.

There is at least one such power field described. The end of input is indicated by a 0 for the number of monuments. The first sample data below corresponds to the diagram in the problem.
输出For each power field there is one line of output. It contains the three labels of the vertices of the power triangle, listed in increasing alphabetical order, with no spaces.

样例输入

6
A 1 0
B 4 0
C 0 3
D 1 3
E 4 4
F 0 6
4
A 0 0
B 1 0
C 99 0
D 99 99
0

样例输出

BEF
BCD

来源

Mid-Central USA 1999

技术分享图片
 1 #include <iostream>
 2 #include <string.h>
 3 #include <algorithm>
 4 #include <stack>
 5 #include <string>
 6 #include <math.h>
 7 #include <queue>
 8 #include <stdio.h>
 9 #include <string.h>
10 #include <set>
11 #include <vector>
12 #include <fstream>
13 #define maxn 10005
14 #define inf 999999
15 #define cha 127
16 #define eps 1e-6
17 using namespace std;
18 
19 struct Vector {
20     char sig;
21     double x, y;
22     Vector(double a, double b) {
23         x = a, y = b;
24     }
25     Vector() {}
26 };
27 #define point Vector
28 point operator -(point a, point b) {
29     return point(a.x - b.x, a.y - b.y);
30 }
31 double cross(Vector v1, Vector v2) {
32     return v1.x*v2.y - v1.y*v2.x;
33 }
34 double area(Vector p1, Vector p2) {
35     return cross(p1, p2) / 2;
36 }
37 point all[20];
38 int n;
39 double Max;
40 char ans[3];
41 
42 int islagerthan0(double x,int isni) {
43     if (fabs(x) < eps)
44         return 1;
45     int f = x > 0; f = f ^ isni;
46     return f;
47 }
48 
49 void solve(int a,int b,int c) {
50     point aa = all[a], bb = all[b], cc = all[c];
51     double ar = fabs(area(bb - aa, cc - aa));
52     if (ar <= Max)return;
53     int isni = (cross(bb - aa, cc - bb) > 0);
54     for (int i = 1; i <= n; i++) {
55         if (i == a || i == b || i == c)
56             continue;
57         bool f1 = islagerthan0(cross(bb - all[i], aa - all[i]), isni);
58         bool f2 = islagerthan0(cross(cc - all[i], bb - all[i]), isni);
59         bool f3 = islagerthan0(cross(aa - all[i], cc - all[i]), isni);
60         if (f1&&f2&&f3)
61             return;
62     }
63     Max = ar;
64     ans[0] = aa.sig, ans[1] = bb.sig, ans[2] = cc.sig;
65 }
66 
67 void init() {
68     Max = 0;
69     for (int i = 1; i <= n; i++)
70         scanf("
%c %lf %lf", &all[i].sig, &all[i].x, &all[i].y);
71     for (int i = 1; i <= n; i++)
72         for (int j = i + 1; j <= n; j++)
73             for (int k = j + 1; k <= n; k++)
74                 solve(i, j, k);
75     sort(ans, ans + 3);
76     for (int i = 0; i < 3; i++)
77         printf("%c", ans[i]);
78     printf("
");
79 }
80 
81 int main() {
82     while (scanf("%d",&n)&&n)
83         init();
84     return 0;
85 }
View Code

WA点:

浮点数判定其大于等于0的方法

再次没有初始化………………

以上是关于18.12.17 POJ 1569 Myacm Triangles的主要内容,如果未能解决你的问题,请参考以下文章

18.12.17 POJ 1269 Intersecting Lines

HDU 1569 方格取数 (最小割)

hdu 1569 方格取数 (网络流)

hdu 1569 &1565 (二分图带权最大独立集 - 最小割应用)

POJ——T 3255 Roadblocks|| COGS——T 315. [POJ3255] 地砖RoadBlocks || 洛谷—— P2865 [USACO06NOV]路障Roadblocks(

POJ——T 3225 Roadblocks