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("\n%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("\n");
79 }
80
81 int main() {
82     while (scanf("%d",&n)&&n)
83         init();
84     return 0;
85 }

WA点:

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

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

原文地址:https://www.cnblogs.com/yalphait/p/10134745.html

时间: 2024-11-08 20:46:23

18.12.17 POJ 1569 Myacm Triangles的相关文章

18.12.17 POJ 1269 Intersecting Lines

描述 We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one anoth

18.12.20 POJ 3661 跑步

描述 奶牛们打算通过锻炼来培养自己的运动细胞,作为其中的一员,贝茜选择的运动方式是每天进行N(1 <= N <= 10,000)分钟的晨跑.在每分钟的开始,贝茜会选择下一分钟是用来跑步还是休息. 贝茜的体力限制了她跑步的距离.更具体地,如果贝茜选择在第i分钟内跑步,她可以在这一分钟内跑D_i(1 <= D_i <= 1,000)米,并且她的疲劳度会增加 1.不过,无论何时贝茜的疲劳度都不能超过M(1 <= M <= 500).如果贝茜选择休息,那么她的疲劳度就会每分钟减

12.17 Nginx负载均衡;12.18 ssl原理;12.19 生产ssl密钥对;12.20 Nginx配置ssl

扩展: 针对请求的uri来代理 http://ask.apelearn.com/question/1049 根据访问的目录来区分后端web http://ask.apelearn.com/question/920 12.17 Nginx负载均衡 1. 安装dig命令: [[email protected] ~]# yum install -y bind-utils 2. 用dig获取qq.com的ip地址: [[email protected] ~]# dig qq.com 3. 创建ld.co

12.17 Nginx负载均衡;12.18 ssl原理;12.19 生产ssl密钥对;12.20 N

12.17 Nginx负载均衡:12.18 ssl原理:12.19 生产ssl密钥对:12.20 Nginx配置ssl 扩展: 针对请求的uri来代理 : http://ask.apelearn.com/question/1049 根据访问的目录来区分后端的web : http://ask.apelearn.com/question/920 nginx长连接 : http://www.apelearn.com/bbs/thread-6545-1-1.html nginx算法分析 : http:/

12.17 Nginx负载均衡 12.18 ssl原理 12.19 生成ssl密钥对 12.20 N

12.17 Nginx负载均衡 [[email protected] ~]# yum install -y bind-utils[[email protected] ~]# dig www.qq.comANSWER SECTION:www.qq.com. 73 IN A 59.37.96.63www.qq.com. 73 IN A 14.17.42.40www.qq.com. 73 IN A 14.17.32.211[[email protected] ~]# curl -x127.0.0.1:

ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)

Description Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, java, pas} Input file: triangle.in Output file: triangle.out There has been considerable archeological work on the ancient Myacm culture. Many artifacts

18.9.17 poj2492 A Bug&#39;s Life

描述 BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their

12.17 ~ 12.23周训练计划+总结

12.17 学一波min25筛 大概会了 裸题: https://www.luogu.org/problemnew/show/SP34096 12.18 上午考试,下午+晚上改题 orz https://www.codechef.com/problems/BTREE 12.19 上午怒刚http://uoj.ac/problem/59和http://uoj.ac/problem/56 没有刚完,大概周末继续 下午睡到2:30,起来听了一波fwt,觉得挺傻逼的 https://lydsy.com/

centos 6.5 升级内核 linux 3.12.17

环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Linux centos 2.6.32-431.el6.x86_64(Centos-6.5-x86_64-minimal.iso ) 升级内核版本:longterm:3.12.17 升级步骤: 1.虚拟系统安装 要求mininal方式安装(205个包),具体步骤省略. 2.查看原有系统内核版本,升级更新包 2.1更新包 [[email protected] ~]# yum update [[email pr