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
73 0
uva10038 Jolly Jumpers
uva10038 Jolly Jumpers
68 0
uva 10340 all in all
输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。
52 0
UVa11776 - Oh Your Royal Greediness!
UVa11776 - Oh Your Royal Greediness!
64 0
UVa 10082 WERTYU
UVa 10082 WERTYU
139 0
|
机器学习/深度学习
|
C++
UVA 之10010 - Where's Waldorf?
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/24863879 ...
723 0
|
人工智能
uva 305 Joseph
点击打开链接uva 305 思路: 数学+打表 分析: 1 传统的约瑟夫问题是给定n个人和m,每次数m次把当前这个人踢出局,问最后留下的一个人的编号 2 这一题是前k个人是好人,后面k个是坏人。
1058 0
uva 10054 - The Necklace
点击打开链接uva 10054 思路: 欧拉回路 分析: 1 对于一个无向图来说如果这个图是一个欧拉图,那么必须满足该图是连通的并且每个点的度数都是偶数 2 题目给定n条边的无向图问我们是否是一个欧拉图,是的话输出欧拉图的一条路径 3 ...
850 0
|
网络协议 JavaScript
uva10125
题意:给出一个数集S中所有元素,问是否存在d属于S使得d=a+b+c,且a,b,c均属于S?若有,则输出最大的d 否则输出no solution 做法:暴力就可以过的。 代码如下: #include #include #include #define zz using nam...
646 0