zoukankan      html  css  js  c++  java
  • WUST Online Judge

    2161: 特殊的三角形

    Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lld
    Submitted: 513  Accepted: 100
    [Submit][Status][Web Board]

    Description

    假如给你三个顶点的坐标,保证这三个顶点一定可以构成三角形,问是否能构成直角三角形?可以的话输出"RIGHT"。好像问题太简单了,为了增加难度,假如我们可以将任意一个顶点的横坐标或者纵坐标加1或者减1(注意我们只能进行一次操作,改变一个顶点的横坐标或者纵坐标),使得可以构成直角三角形的话,输出"ALMOST"。其他情况输出"NEITHER"。
    题目输入保证坐标都是整数。

    Input

    多组输入
    输入三个坐标,x1,y1,x2,y2,x3,y3,保证都是整数并在int范围内。

    Output

    输出结果。

    Sample Input

    0 0 2 0 0 1
    2 3 4 5 6 6

    Sample Output

    RIGHT
    NEITHER
    

    Author

    CYL

    代码如下:

    #include <stdio.h>
    
    int f(int a, int b, int c, int d, int e, int f) {
        if (((c-a)*(c-a)+(d-b)*(d-b))+((e-a)*(e-a)+(f-b)*(f-b))==((e-c)*(e-c)+(f-d)*(f-d)))
            return 1;
        else if (((e-a)*(e-a)+(f-b)*(f-b))+((e-c)*(e-c)+(f-d)*(f-d))==((c-a)*(c-a)+(d-b)*(d-b)))
            return 1;
        else if (((e-c)*(e-c)+(f-d)*(f-d))+((c-a)*(c-a)+(d-b)*(d-b))==((e-a)*(e-a)+(f-b)*(f-b)))
            return 1;
        else return 0;
    }
    int main(void) {
        int x1, x2, x3, y1, y2, y3, flag, temp;
        while (scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3) != EOF) {
            flag = 1; temp = 1;
            if (f(x1, y1, x2, y2, x3, y3)) {
                printf("RIGHT
    ");
                temp = 0;
            }
            else if (temp && flag && (f(x1 - 1, y1, x2, y2, x3, y3) || f(x1 + 1, y1, x2, y2, x3, y3))) flag = 0;
            else if (temp && flag && (f(x1, y1 - 1, x2, y2, x3, y3) || f(x1, y1 + 1, x2, y2, x3, y3))) flag = 0;
            else if (temp && flag && (f(x1, y1, x2 - 1, y2, x3, y3) || f(x1, y1, x2 + 1, y2, x3, y3))) flag = 0;
            else if (temp && flag && (f(x1, y1, x2, y2 - 1, x3, y3) || f(x1, y1, x2, y2 + 1, x3, y3))) flag = 0;
            else if (temp && flag && (f(x1, y1, x2, y2, x3 - 1, y3) || f(x1, y1, x2, y2, x3 + 1, y3))) flag = 0;
            else if (temp && flag && (f(x1, y1, x2, y2, x3, y3 - 1) || f(x1, y1, x2, y2, x3, y3 + 1))) flag = 0;
            if (!flag) {
                printf("ALMOST
    ");
                temp = 0;
            }
            else if (temp) printf("NEITHER
    ");
        }
        return 0;
    }
    
    作者:McR
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    加载时间分析与优化
    t
    linux 3389
    切片声明 切片在内存中的组织方式 reslice
    从模版生成 uri Golang 的 html/template 包不太适合于这种情况
    负载均衡实现,一个域名对应多个IP地址
    京东首页 淘宝首页 图片加载 单域名 多域名 图片服务
    Reduce DNS Lookups 减少DNS查找
    Make Fewer HTTP Requests 减少HTTP请求
    What the 80/20 Rule Tells Us about Reducing HTTP Requests
  • 原文地址:https://www.cnblogs.com/mcr-tcp/p/9170726.html
Copyright © 2011-2022 走看看