zoukankan      html  css  js  c++  java
  • King's Sanctuary(简单几何)

    King's Sanctuary

    Time Limit: 1000 ms Memory Limit: 65535 kB Solved: 111 Tried: 840

    Submit

    Status

    Best Solution

    Back

    Description

     

    The king found his adherents were building four sanctuaries for him. He is interested about the positions of the sanctuaries and wants to know whether they would form a parallelogram, rectangle, diamond, square or anything else.

     

    Input

     

    The first line of the input is T(1 <= T <= 1000), which stands for the number of test cases you need to solve.
    Each case contains four lines, and there are two integers in each line, which shows the position of the four sanctuaries. And it is guaranteed that the positions are given clockwise. And it is always a convex polygon, if you connect the four points clockwise.

     

    Output

     

    For every test case, you should output "Case #t: " first, where t indicates the case number and counts from 1, then output the type of the quadrilateral.

     

    Sample Input

     

    5
    0 0
    1 1
    2 1
    1 0
    0 0
    0 1
    2 1
    2 0
    0 0
    2 1
    4 0
    2 -1
    0 0
    0 1
    1 1
    1 0
    0 0
    1 1
    2 1
    3 0

     

    Sample Output

     

    Case #1: Parallelogram
    Case #2: Rectangle
    Case #3: Diamond
    Case #4: Square
    Case #5: Others

     

    Source

     

    Sichuan State Programming Contest 2012

    步骤:1.判断是否平行四边形,不是则为others,是则执行2;2.判断是否菱形,是否长方形,都是则为正方形,都不是则为平行四边形,其一是另一否,则是菱形或长方形。

     1 #include <iostream>
     2 #include <queue>
     3 #include <vector>
     4 #include <map>
     5 #include <string>
     6 #include <algorithm>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <cmath>
    10 
    11 using namespace std;
    12 
    13 int T, x[4], y[4];
    14 
    15 bool Parallelogram()
    16 {
    17     int a = (y[1] - y[0]) * (x[3] - x[2]);
    18     int b = (x[1] - x[0]) * (y[3] - y[2]);
    19     if(a != b) return false;
    20     a = (x[2] - x[1]) * (y[3] - y[0]);
    21     b = (x[3] - x[0]) * (y[2] - y[1]);
    22     return a == b;
    23 }
    24 
    25 bool Rectangle()
    26 {
    27     int a = (x[0] - x[2]) * (x[0] - x[2]) + (y[0] - y[2]) * (y[0] - y[2]);
    28     int b = (x[1] - x[3]) * (x[1] - x[3]) + (y[1] - y[3]) * (y[1] - y[3]);
    29     return a == b;
    30 }
    31 
    32 bool Diamond()
    33 {
    34     int a = (y[0] - y[2]) * (y[1] - y[3]);
    35     int b = (x[1] - x[3]) * (x[0] - x[2]);
    36     return a == -b;
    37 }
    38 
    39 int main()
    40 {
    41     scanf("%d", &T);
    42     for(int ca = 1; ca <= T; ca++)
    43     {
    44         int i, j;
    45         for(i = 0; i < 4; i++)
    46         {
    47             scanf("%d %d", &x[i], &y[i]);
    48         }
    49         printf("Case #%d: ", ca);
    50         for(i = 0; i < 4; i++)
    51         {
    52             for(j = i + 1; j < 4; j++)
    53             {
    54                 if(x[i] == x[j] && y[i] == y[j])
    55                     break;
    56             }
    57             if(j != 4) break;
    58         }
    59         if(i != 4) puts("Others");
    60         else
    61         {
    62             bool tag, tag1;
    63             tag = Parallelogram();
    64             if(tag == false) {puts("Others");}
    65             else
    66             {
    67                 tag = Rectangle();
    68                 tag1 = Diamond();
    69                 if(tag == false && tag1 == false) puts("Parallelogram");
    70                 else if(tag == true && tag1 == true) puts("Square");
    71                 else if(tag == true) puts("Rectangle");
    72                 else if(tag1 == true) puts("Diamond");
    73             }
    74         }
    75     }
    76     return 0;
    77 }
  • 相关阅读:
    android http多请求异步封装对你绝对有用
    浅论Android网络请求库——android-async-http
    Android Http异步请求,Callback
    STL慎重选择删除元素的
    iOS开展
    【Bootstrap】兼容IE8、谷歌和其他主流浏览器的观众IMAX风格的页面
    Codeforces #180 div2 C Parity Game
    vS2010 列表控件 加入右键菜单
    cocos2d-x 3.2 2048——第六部分(最后一章)
    E: 无法获取锁 /var/lib/apt/lists/lock
  • 原文地址:https://www.cnblogs.com/cszlg/p/3220709.html
Copyright © 2011-2022 走看看