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;
}
目录
相关文章
|
6月前
uva 10340 all in all
输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。
21 0
|
8月前
UVa11776 - Oh Your Royal Greediness!
UVa11776 - Oh Your Royal Greediness!
36 0
UVa 10082 WERTYU
Problem Description A common typing error is to place the hands on the keyboard one row to the right of the correct position.
861 0
|
机器学习/深度学习
|
C++
UVA 之10010 - Where's Waldorf?
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/24863879 ...
685 0
|
人工智能
uva 305 Joseph
点击打开链接uva 305 思路: 数学+打表 分析: 1 传统的约瑟夫问题是给定n个人和m,每次数m次把当前这个人踢出局,问最后留下的一个人的编号 2 这一题是前k个人是好人,后面k个是坏人。
1009 0
uva 1160 X-Plosives
点击打开链接uva 1160 思路: 并查集 分析: 1 看懂题目之和就是切菜了 代码: #include #include #include #include using namespace std; const int MAXN...
749 0
|
人工智能
uva 10189 Minesweeper
/* Minesweeper WA了n次才知道uva格式错了也返回wa没有pe啊尼玛 */ #include&lt;iostream&gt; #include&lt;stdio.h&gt; #include&lt;string.h&gt; using namespace std; char a[105][105]; int main() { int i,j,n,m,
915 0
uva 10730 - Antiarithmetic?
点击打开链接uva 10730 思路:枚举等差中项 分析: 1 给定一个n个数的序列判断是否有等差子序列 2 很明显我们如果要判断是否有等差子序列的话,只要去判断是否有长度为3的等差子序列 3 对于n
814 0

热门文章

最新文章