uva10112 Myacm Triangles

简介: uva10112 Myacm Triangles
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#define LOCALtypedefstructPoint{
charlabel;
intx;
inty;
}point;
pointPoints[20];
intsearch[500][3];
intc;
inttemp[3];
intvisited[30];
voiddfs(intpos, intn);
doublearea(pointa, pointb, pointc);
intinside_triangle(pointa, pointb, pointc, pointd);
intcross(pointa, pointb, pointc);
intmain()
{
inttests;
inti, j;
pointtriangle[3];
intnodeVis[20];
doubles ;
intok;
doubletemp;
charans[3];
#ifdef LOCALfreopen("c://uva_in.txt", "r", stdin);
#endifwhile (scanf("%d", &tests) &&tests!=0)
    {
c=0;
s=-1.0;
memset(visited, 0, sizeof(visited));
dfs(0, tests);
fgetc(stdin);
for (i=1; i<=tests; i++)
        {
scanf("%c%d%d", &(Points[i].label), &(Points[i].x), &(Points[i].y));
fgetc(stdin);
        }
for (i=0; i<c; i++)
        {
memset(nodeVis, 0, sizeof(nodeVis));
for (j=0; j<3; j++)
            {
nodeVis[search[i][j]] =1;
triangle[j].label=Points[search[i][j]].label;
triangle[j].x=Points[search[i][j]].x;
triangle[j].y=Points[search[i][j]].y;
            }
ok=1;
for (j=1; j<=tests; j++)
            {
if (!nodeVis[j])
                {
if (inside_triangle(triangle[0], triangle[1], triangle[2], Points[j]))
                    {
ok=0;
break;
                    }
                }
            }
temp=area(triangle[0], triangle[1], triangle[2]);
if (ok&& (temp>s))
            {
s=temp;
ans[0] =triangle[0].label;
ans[1] =triangle[1].label;
ans[2] =triangle[2].label;
            }
        }
for (i=0; i<3; i++)
printf("%c", ans[i]);
printf("/n");
    }
return0;
}
voiddfs(intpos, intn)
{
inti;
if (pos==3)
    {
search[c][0] =temp[0];
search[c][1] =temp[1];
search[c][2] =temp[2];
c++;
    } else    {
for (i=1; i<=n; i++)
        {
if (!visited[i] && (i>temp[pos-1]))
            {
visited[i] =1;
temp[pos] =i;
dfs(pos+1, n);
visited[i] =0;
            }
        }
    }
}
doublearea(pointa, pointb, pointc)
{
intx1, y1, x2, y2;
doubles;
x1=b.x-a.x;
y1=b.y-a.y;
x2=c.x-a.x;
y2=c.y-a.y;
s=fabs(x1*y2-y1*x2) /2.0;
returns;
}
intinside_triangle(pointa, pointb, pointc, pointd)
{
if ((cross(a, b, d) >=0&&cross(b, c, d) >=0&&cross(c, a, d) >=0) || (cross(a, b, d) <=0&&cross(b, c, d) <=0&&cross(c, a, d) <=0))
return1;
elsereturn0;
}
intcross(pointa, pointb, pointc)
{
intx1, y1, x2, y2;
inttemp;
x1=b.x-a.x;
y1=b.y-a.y;
x2=c.x-a.x;
y2=c.y-a.y;
temp=x1*y2-x2*y1;
returntemp;
}
目录
相关文章
|
9月前
|
人工智能 程序员 测试技术
通义灵码 AI 程序员核心功能体验
阿里云通义灵码AI程序员已全面上线,成为全球首个同时支持 VS Code、JetBrains IDEs 开发工具的AI程序员产品。
1243 1
通义灵码 AI 程序员核心功能体验
|
Java 数据库连接 Apache
Hutool工具包等常用工具类总结
Hutool工具包等常用工具类总结
1614 0
|
JSON JavaScript 定位技术
Echarts 绘制地图(中国、省市、区县),保姆级教程!
Echarts 绘制地图(中国、省市、区县),保姆级教程!
|
前端开发 Android开发 开发者
移动应用开发的未来:跨平台框架与原生系统之争
【4月更文挑战第27天】 随着智能手机的普及,移动应用开发成为软件工程的一个热点。本文探讨了当前移动应用开发的两大趋势:跨平台移动应用框架和原生操作系统应用。分析了Flutter、React Native等跨平台工具的优势与局限,同时评估了iOS和Android各自在性能、用户体验和生态系统方面的特点。通过对比这些技术,文章旨在为开发者提供一个关于选择何种开发策略的指导视角,并对未来移动应用开发的发展趋势做出预测。
|
安全 网络安全 数据安全/隐私保护
数据通信网络基础
该文档介绍了网络通信的基本概念,包括通信是信息传递与交流的过程,网络通信则是通过计算机网络在终端设备间进行的通信。文中列举了网络通信的例子,并详细解释了几个关键术语:交换机(用于终端用户接入,数据帧交换),路由器(网络层设备,数据报文转发),防火墙(网络安全设备,隔离并控制网络流量)。此外,还提到了无线设备(如胖AP和瘦AP)以及网络类型(局域网、城域网、广域网)和网络拓扑的概念,包括星型、总线型、环型等不同拓扑结构的特点和优缺点。
C# “文件选择对话框“ 和 “保存对话框“
C# “文件选择对话框“ 和 “保存对话框“
|
缓存 JavaScript 算法
v-if和v-show的区别及源码分析
v-if和v-show的区别及源码分析
274 1
|
编译器 C++ 存储
【C++修炼之路】3. 类和对象(中)
【C++修炼之路】3. 类和对象(中)
【C++修炼之路】3. 类和对象(中)
html播放音频标签(兼容ie,谷歌)
html播放音频标签(兼容ie,谷歌)
164 0
|
SQL 分布式计算 关系型数据库
Sqoop导入数据
Sqoop导入数据样例
246 0