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;
}
目录
相关文章
Uva10001 Garden of Eden
Uva10001 Garden of Eden
47 0
uva10152 ShellSort
uva10152 ShellSort
63 0
UVa11776 - Oh Your Royal Greediness!
UVa11776 - Oh Your Royal Greediness!
56 0
UVa 10082 WERTYU
UVa 10082 WERTYU
129 0
|
机器学习/深度学习
uva 11538 Chess Queen
点击打开链接 题意:给定一个n*m的矩阵,问有多少种方法放置两个相互攻击的皇后?规定在同一行同一列和同对角线的能够相互攻击 思路: 1 先考虑同一行的情况,n行就有n种情况,每一行有m*(m-1)种,总的是n*m*(m-1); 2 考虑同...
820 0
uva 1203 Argus
点击打开链接uva 1203 思路: 优先队列 分析: 1 题目要求前k个事件的编号,我们利用优先队列来维护即可 2 优先队列保存的是一个struct,因此我们需要重载 s.
1296 0
uva 1160 X-Plosives
点击打开链接uva 1160 思路: 并查集 分析: 1 看懂题目之和就是切菜了 代码: #include #include #include #include using namespace std; const int MAXN...
772 0
uva 1394 - And Then There Was One
点击打开链接uva 1394 思路: 数学递推 分析: 1 题目是一道变形的约瑟夫环变形问题 2 网上看到一篇很好的数学递推法 问题描述:n个人(编号0~(n-1)),从0开始报数,报到(m-1)的退出,剩下的人继续从0开始报数。
995 0
uva 10730 - Antiarithmetic?
点击打开链接uva 10730 思路:枚举等差中项 分析: 1 给定一个n个数的序列判断是否有等差子序列 2 很明显我们如果要判断是否有等差子序列的话,只要去判断是否有长度为3的等差子序列 3 对于n
846 0