现在的位置: 首页 > 综合 > 正文

B. Eight Point Sets

2014年03月01日 ⁄ 综合 ⁄ 共 1684字 ⁄ 字号 评论关闭
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 0
0 1
0 2
1 0
1 2
2 0
2 1
2 2
output
respectable
input
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
output
ugly
input
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 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;
}

抱歉!评论已关闭.