Description
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x1, x2, x3 and three more integers y1, y2, y3, such that x1 < x2 < x3, y1 < y2 < y3 and the eight point set consists of all points (xi, yj) (1 ≤ i, j ≤ 3), except for point (x2, y2).
You have a set of eight points. Find out if Gerald can use this set?
Input
The input consists of eight lines, the i-th line contains two space-separated integers xi and yi (0 ≤ xi, yi ≤ 106). You do not have any other conditions for these points.
Output
In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise.
Sample Input
0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2
respectable
0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0
ugly
1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2
ugly
#include<stdio.h>
int x[10],y[10];
bool judge(){
int i,j;
for(i=1;i<8;i++)
for(j=i+1;j<=8;j++)
if(x[i]>x[j] || (x[i]==x[j] && y[i]>y[j])){
int tmp=x[i];
x[i]=x[j];
x[j]=tmp;
tmp=y[i];
y[i]=y[j];
y[j]=tmp;
}
if(x[1]!=x[2] || x[2]!=x[3])
return false;
if(x[4]!=x[5])
return false;
if(x[6]!=x[7] || x[7]!=x[8])
return false;
if(x[3]==x[4])
return false;
if(x[5]==x[6])
return false;
if(y[1]!=y[4] || y[4]!=y[6])
return false;
if(y[2]!=y[7])
return false;
if(y[3]!=y[5] || y[5]!=y[8])
return false;
if(y[1]==y[2] || y[2]==y[3])
return false;
return true;
}
int main(){
int i;
for(i=1;i<=8;i++)
scanf("%d%d",&x[i],&y[i]);
if(judge())
printf("respectable\n");
else
printf("ugly\n");
return 0;
}
本文介绍了一种用于验证特定八点集是否符合预定义规则的算法。这些规则要求点集由三条不同整数水平线与三条不同整数垂直线的所有交点构成,但排除了这些线相交形成的九个点的中点。文中提供了输入输出示例及完整的C语言实现代码。
2万+

被折叠的 条评论
为什么被折叠?



