B. Eight Point Sets

来源:互联网 发布:mac上邮箱怎么设置 编辑:程序博客网 时间:2024/04/29 20:05

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 < x3y1 < 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 test(s)
input
0 00 10 21 01 22 02 12 2
output
respectable
input
0 01 02 03 04 05 06 07 0
output
ugly
input
1 11 21 32 12 22 33 13 2
output
ugly


解题说明:给你满足x1<x2<x3, y1<y2<y3, 然后用这六个数组成九个点,去掉(x2,y2)点,剩下的八个点是否满足条件。首先对这八个点排序,然后按照从中找到x1,x2,x3,y1,y2,y3,判断是否满足条件。


#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>int compare(const void *a,const void *b){    return (*(int *)a-*(int *)b);}int main(){    int x[8],y[8],i,j;    for(i=0;i<8;i++)    {        scanf("%d %d",&x[i],&y[i]);    }    for(i=0;i<8;i++)    {        for(j=i+1;j<8;j++)        {   if(x[i]==x[j]&&y[i]==y[j])            {                printf("ugly");                return 0;            }            else            {continue;}}    }    qsort(x,8,sizeof(int),compare);    qsort(y,8,sizeof(int),compare);    if(x[1]==x[0]&&x[2]==x[1]&&x[4]==x[3]&&x[7]==x[6]&&x[5]==x[7]&&x[3]>x[0]&&x[6]>x[3]&&y[3]>y[2]&&y[5]>y[4]&&y[4]==y[3]&&y[0]==y[1]&&y[1]==y[2]&&y[6]==y[7]&&y[5]==y[6]&&y[3]!=y[1])    {printf("respectable\n");}else{        printf("ugly\n");}return 0;}


原创粉丝点击