Uva 10112 Myacm Triangles

本文概述了AI音视频处理领域的关键技术,包括视频分割、语义识别、自动驾驶、AR、SLAM等,并探讨了其在实际应用中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 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.

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

题目大意:

给你一些点叫你算出,面积最大而且内部不含其余点的三角形。


题目解析:

可以枚举出所有可能的三角形,在判断三角形内部是否含有点

题目里告诉我们面积所以首相想到面积法,设三角形abc,还有一点o 如果Sabc=Sab+Saco+Sbco

则o在三角形内部或边上否则在三角形外部


#include <stdio.h>
#include <math.h>
const int N = 20;
struct In {
	char ch;
	int x;
	int y;
};
In in[N];

double area(In p1,In p2,In p3) {
	return fabs( 0.5 * ( (p3.y - p1.y)*(p2.x - p1.x) - (p2.y - p1.y)*(p3.x - p1.x) ));
}

int main() {
	int t;
	while(scanf("%d",&t) != EOF , t) {
		getchar();
		for(int i=0;i<t;i++) {
			in[i].ch = getchar();
			scanf("%d%d",&in[i].x,&in[i].y); getchar();
		}
		double max = -0x3f3f3f;
		double sum,tmp;
		bool flag;
		int A,B,C;
		for(int i = 0; i < t; i++) {
			for(int j = i+1; j < t; j++) {
				for(int k = j+1; k < t; k++) {

					sum = area(in[i],in[j],in[k]);

					flag = true;
					for(int l = 0; l < t; l++) {
						if( l == i || l == j || l == k) //如果其中一点是三点中的任意一点,则不用考虑
							continue;
						tmp = area(in[i],in[j],in[l]) + area(in[i],in[k],in[l]) + area(in[j],in[k],in[l]);
			
						if( tmp == sum ) {
							flag = false;
							break;
						}
					}

					if(sum > max && flag) {
						max = sum;
						A = i;
						B = j;
						C = k;
					}
				}
			}
		}
		printf("%c%c%c\n",in[A].ch,in[B].ch,in[C].ch);
	}
	return 0;
}



### 使用 `GL_TRIANGLES` 模式绘制三角形 在 OpenGL 中,`GL_TRIANGLES` 是一种用于定义多个独立三角形的方式。当使用此模式时,每三个连续的顶点构成一个单独的三角形[^1]。 对于 `glDrawArrays(GL_TRIANGLES, startIndex, count)` 函数调用: - 参数 `startIndex` 表示从哪个索引位置开始读取顶点数据。 - 参数 `count` 定义要处理多少个顶点;由于每个三角形由三个顶点组成,因此实际绘制的三角形数量等于 `count / 3` 向下取整的结果。 下面是一个简单的例子来展示如何利用 C++ 和 OpenGL 来创建并渲染两个相连但不共享任何边界的三角形: ```cpp // 假设已经初始化好了OpenGL环境,并绑定了VBO和VAO等必要对象 float vertices[] = { // 第一个三角形 0.5f, 0.5f, 0.0f, // 右上角 0.5f, -0.5f, 0.0f, // 右下角 -0.5f, -0.5f, 0.0f, // 左下角 // 第二个三角形 -0.5f, -0.5f, 0.0f, // 左下角 -0.5f, 0.5f, 0.0f, // 左上角 0.5f, 0.5f, 0.0f // 右上角 }; GLuint VBO; glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // 设置顶点属性指针... glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // 渲染命令 glDrawArrays(GL_TRIANGLES, 0, 6); // 此处我们有六个顶点,形成两个三角形 ``` 这段代码片段展示了怎样通过指定六组坐标值(即两个分离的三角形),并通过一次绘图指令完成它们的同时显示。值得注意的是,在这种情况下,即使第二个三角形的第一个顶点与第一个三角形最后一个相同,也必须重复提供该顶点的信息,因为这些三角形之间没有任何连接关系[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值