B. Eight Point Sets
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?
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.
In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise.
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
刚开始没看懂意思,其实就是,给你满足x1<x2<x3, y1<y2<y3, 然后用这六个数组成九个点,去掉(x2,y2)点,剩下的八个点是否满足条件:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node{ int x,y; }p[8]; int a[10],b[10]; int cmp(node a,node b){ if(a.x==b.x) return a.y<b.y; return a.x<b.x; } int main() { //freopen("input.txt","r",stdin); while(~scanf("%d%d",&p[0].x,&p[0].y)){ a[0]=p[0].x, b[0]=p[0].y; int cnt1=1,cnt2=1; for(int i=1;i<8;i++){ scanf("%d%d",&p[i].x,&p[i].y); int flag1=1,flag2=1; for(int j=0;j<cnt1;j++) if(p[i].x==a[j]) flag1=0; if(flag1) a[cnt1++]=p[i].x; for(int j=0;j<cnt2;j++) if(p[i].y==b[j]) flag2=0; if(flag2) b[cnt2++]=p[i].y; } if(cnt1!=3 || cnt2!=3){ //判断点x==3? 点y==3? puts("ugly"); continue; } sort(a,a+3); sort(b,b+3); if(a[0]==a[1] || a[1]==a[2] || b[0]==b[1] || b[1]==b[2]){ //是否满足x1<x2<x3 且 y1<y2<y3 puts("ugly"); continue; } sort(p,p+8,cmp); int flag=1,cnt=0; for(int i=0;i<3;i++) for(int j=0;j<3;j++){ //和输出对拍,看看是否相同 if(i==1 && j==1) //去掉点(x2,y2) continue; if(a[i]==p[cnt].x && b[j]==p[cnt].y) cnt++; else{ flag=0; break; } } if(flag) puts("respectable"); else puts("ugly"); } return 0; }