B. Eight Point Sets
1 second
256 megabytes
standard input
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 < 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[]; int a[],b[]; 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[].x,&p[].y)){
a[]=p[].x, b[]=p[].y;
int cnt1=,cnt2=;
for(int i=;i<;i++){
scanf("%d%d",&p[i].x,&p[i].y);
int flag1=,flag2=;
for(int j=;j<cnt1;j++)
if(p[i].x==a[j])
flag1=;
if(flag1)
a[cnt1++]=p[i].x;
for(int j=;j<cnt2;j++)
if(p[i].y==b[j])
flag2=;
if(flag2)
b[cnt2++]=p[i].y;
}
if(cnt1!= || cnt2!=){ //判断点x==3? 点y==3?
puts("ugly");
continue;
}
sort(a,a+);
sort(b,b+);
if(a[]==a[] || a[]==a[] || b[]==b[] || b[]==b[]){ //是否满足x1<x2<x3 且 y1<y2<y3
puts("ugly");
continue;
}
sort(p,p+,cmp);
int flag=,cnt=;
for(int i=;i<;i++)
for(int j=;j<;j++){ //和输出对拍,看看是否相同
if(i== && j==) //去掉点(x2,y2)
continue;
if(a[i]==p[cnt].x && b[j]==p[cnt].y)
cnt++;
else{
flag=;
break;
}
}
if(flag)
puts("respectable");
else
puts("ugly");
}
return ;
}
最新文章
- javascript call与apply关键字的作用
- 【BZOJ1984】月下“毛景树” 树链剖分+线段树
- [算法导论]DFS @ Python
- C/C++的一些备忘
- Xcode7.01相对于底版本的变动小结
- JLRoutes--处理复杂的URL schemes-备
- 安装dnvm
- CSS 实现的各种球体效果
- HDU 1159 Common Subsequence【dp+最长公共子序列】
- 扩展 KMP
- java开源安全框架-------Apache Shiro--第一天
- python—DAY1
- pip 安装第三方包提示Unknown or unsupported command &#39;install&#39;
- NN 激活函数 待修改
- 一篇自己都看不懂的Matrix tree总结
- hdu5157 Harry and magic string【manacher】
- leetcode python 001
- [Proposal]Transform ur shapes!
- CRM项目完成实现
- [翻译] PTEHorizontalTableView