首页 > 其他分享 >UVa 10112 Myacm Triangles (枚举&计算几何)

UVa 10112 Myacm Triangles (枚举&计算几何)

时间:2023-04-12 13:03:35浏览次数:54  
标签:triangle power area int monuments ++ UVa 10112 Myacm


10112 - Myacm Triangles

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_problem&problem=1053




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 (x1y1), (x2y2), and (x3y3) is the absolute value of

0.5 × [( y 3  -  y 1)( x 2  -  x 1)  - ( y 2  -  y 1)( x 3  -  x 1)].

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.

Example input:

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

Example output:

BEF BCD

直接O(N^3)枚举。


完整代码:

/*0.022s*/

#include <cstdio>
#include <cstdlib>
const int maxn = 100000;

struct P
{
	char id;
	int x, y;
} p[20];

int ra, rb, rc, n, max;

inline int area(int a, int b, int c)
{
	return abs((p[c].y - p[a].y) * (p[b].x - p[a].x) - (p[b].y - p[a].y) * (p[c].x - p[a].x));
}

inline void judge(int a, int b, int c)
{
	int tmp = area(a, b, c);
	for (int i = 0; i < n; i++)
	{
		if (i == a || i == b || i == c) continue;
		if (area(i, a, b) + area(i, a, c) + area(i, b, c) == tmp) return;
	}
	if (max < tmp)
	{
		max = tmp;
		ra = a, rb = b, rc = c;
	}
}

int main()
{
	while (scanf("%d\n", &n), n)
	{
		max = 0;
		for (int i = 0; i < n; i++)
			scanf("%c%d%d\n", &p[i].id, &p[i].x, &p[i].y);
		for (int i = 0; i < n; i++)
			for (int j = i + 1; j < n; j++)
				for (int k = j + 1; k < n; k++)
					judge(i, j, k);
		printf("%c%c%c\n", p[ra].id, p[rb].id, p[rc].id);
	}
	return 0;
}




标签:triangle,power,area,int,monuments,++,UVa,10112,Myacm
From: https://blog.51cto.com/u_5535544/6185488

相关文章

  • UVa 374 Big Mod (快速幂取模)
    374-BigModTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=310Calculateforlargevaluesof B, P,and M usinganefficientalgorithm.(That'sright,......
  • UVa 112 Tree Summing (scanf()去空格&递归&二叉树遍历)
    112-TreeSummingTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=48BackgroundLISPwasoneoftheearliesthigh-levelprogramminglanguagesand,withFORTRAN,isoneoft......
  • UVa 10161 Ant on a Chessboard (简单数学)
    10161-AntonaChessboardTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1102Background  Oneday,anantcalledAlicecametoanM*Mchessboard.Shewan......
  • UVa 113 / POJ 2109 Power of Cryptography (使用double处理大整数&泰勒公式与误差分
    113-PowerofCryptographyTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=49http://poj.org/problem?id=2109题意:给出n和p,求出 ,但是p可以很大()如何存储p?不用大数可不可以?先看看double......
  • UVa 457 Linear Cellular Automata (water ver.)
    457-LinearCellularAutomataTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=398AbiologistisexperimentingwithDNAmodificationofbacterialcolonies......
  • UVa 489 Hangman Judge (模拟&字符串匹配)
    489-HangmanJudgeTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=430In``HangmanJudge,''youaretowriteaprogramthatjudgesaseriesofH......
  • UVa 10783 Odd Sum (water ver.)
    10783-OddSumTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem&problem=1724Givenarange [a, b],youaretofindthesummationofalltheoddintegersinthisran......
  • UVa 524 Prime Ring Problem (数论&DFS)
    524-PrimeRingProblemTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=465Aringiscomposedofn(evennumber)circlesasshownindiagram.Putnaturalnumbers  intoea......
  • UVa 696 How Many Knights (想法题)
    696-HowManyKnightsTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=637Theknightisapieceusedinchess,agameplayedonaboardwithsquaresarrangedinrowsandcolumns.Aknight......
  • UVa 10785 The Mad Numerologist (排序)
    10785-TheMadNumerologistTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=1726Numerologyisasciencethatisusedbymanypeopletofindoutamansper......