Codeforces Beta Round #18 (Div. 2 Only)——A
2013-01-29 16:24
309 查看
A. Triangle
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them
with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled,
but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should
find out if it is right-angled, almost right-angled, or neither of these.
Input
The first input line contains 6 space-separated integers x1, y1, x2, y2, x3, y3 —
coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.
Output
If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST,
and if it is neither of these, outputNEITHER.
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them
with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled,
but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should
find out if it is right-angled, almost right-angled, or neither of these.
Input
The first input line contains 6 space-separated integers x1, y1, x2, y2, x3, y3 —
coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.
Output
If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST,
and if it is neither of these, outputNEITHER.
#include <cstdio> #include <algorithm> #include <iostream> #include <cmath> #define maxn 5 using namespace std; struct node { int x,y; } a[maxn]; int dx[4]= {-1,0,1,0},dy[4]= {0,-1,0,1}; //四个方向坐标 int dis(int x1,int y1,int x2,int y2) { return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);//You should use squared distances instead of taking roots to overcome problems related to precision errors } bool isright(int x1,int y1,int x2,int y2,int x3,int y3) { int s1=dis(x1,y1,x2,y2); int s2=dis(x2,y2,x3,y3); int s3=dis(x1,y1,x3,y3); if(s1==0||s2==0||s3==0) return 0; if(s1==s2+s3||s2==s1+s3||s3==s1+s2) return 1; else return 0; } int main() { bool flag=false; for(int i=1; i<=3; i++) scanf("%d%d",&a[i].x,&a[i].y); if(isright(a[1].x,a[1].y,a[2].x,a[2].y,a[3].x,a[3].y)) { printf("RIGHT\n"); return 0; } else { for(int i=0; i<4; i++) { int x=a[1].x+dx[i],y=a[1].y+dy[i]; if(isright(x,y,a[2].x,a[2].y,a[3].x,a[3].y)) flag=true; } for(int i=0; i<4; i++) { int x=a[2].x+dx[i],y=a[2].y+dy[i]; if(isright(x,y,a[1].x,a[1].y,a[3].x,a[3].y)) flag=true; } for(int i=0; i<4; i++) { int x=a[3].x+dx[i],y=a[3].y+dy[i]; if(isright(x,y,a[2].x,a[2].y,a[1].x,a[1].y)) flag=true; } } if(flag) printf("ALMOST\n"); else printf("NEITHER\n"); return 0; }
相关文章推荐
- Codeforces Beta Round #18 (Div. 2 Only) D - Seller Bob
- Codeforces Beta Round #18 (Div. 2 Only)——C
- Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)
- Codeforces Beta Round #75 (Div. 2 Only) A题
- Codeforces Beta Round #75 (Div. 1 Only) A题
- Codeforces Beta Round #6 (Div. 2 Only)
- Codeforces Beta Round #87 (Div. 2 Only) A题
- Codeforces Beta Round #92 (Div. 2 Only) B. Permutations
- Codeforces Beta Round #92 (Div. 1 Only)
- Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题
- Codeforces Beta Round #16 (Div. 2 Only)——C
- Codeforces Beta Round #69 (Div. 2 Only) E题
- Codeforces Beta Round #73 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新
- Codeforces Beta Round #69 (Div. 1 Only) C. Beavermuncher-0xFF 树上贪心
- Codeforces Beta Round #80 (Div. 2 Only)
- Codeforces Beta Round #69 (Div. 2 Only)——A,B,D
- Codeforces Beta Round #92 (Div. 2 Only) B. Permutations 模拟
- Codeforces Beta Round #75 (Div. 1 Only)---B.Queue
- Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dp