UESTC93 King's Sanctuary

King's Sanctuary

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

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 TT(1T10001≤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 tt indicates the case number and counts from 11, then output the type of the quadrilateral.

Sample input and output

Sample InputSample Output
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
Case #1: Parallelogram
Case #2: Rectangle
Case #3: Diamond
Case #4: Square
Case #5: Others

 

判断 平行四边形 矩形 菱形 正方形

题解:一步步来  先判断是不是平行四边形再判断是不是矩形和菱形  如果既是矩形也是菱形  那么 就是正方形,否则分别判断是矩形 还是菱形。。具体看代码

/* ***********************************************
Author        :guanjun
Created Time  :2016/7/15 15:30:29
File Name     :1.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
    int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
    }
};

bool cmp(int a,int b){
    return a>b;
}
int x[5];
int y[5];
bool judge_Parallelogram(){
    //1,2   4,3
    int a=(x[2]-x[1])*(y[3]-y[4])-(x[3]-x[4])*(y[2]-y[1]);
    if(a!=0)return 0;
    a=(x[3]-x[2])*(y[4]-y[1])-(x[4]-x[1])*(y[3]-y[2]);
    if(a!=0)return 0;
    return 1;
}
bool judge_Rectangle(){
    int a=(x[3]-x[1])*(x[3]-x[1])+(y[3]-y[1])*(y[3]-y[1]);
    int b=(x[2]-x[4])*(x[2]-x[4])+(y[2]-y[4])*(y[2]-y[4]);
    if(a==b)return 1;
    return 0;
}
bool judge_Diamond(){
    int a=(x[2]-x[1])*(x[2]-x[1])+(y[2]-y[1])*(y[2]-y[1]);
    int b=(x[3]-x[2])*(x[3]-x[2])+(y[3]-y[2])*(y[3]-y[2]);
    if(a==b)return 1;
    return 0;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    int t;
    cin>>t;
    int cas=0;
    while(t--){
        for(int i=1;i<=4;i++){
            cin>>x[i]>>y[i];
        }
        printf("Case #%d: ",++cas);
        if(judge_Parallelogram()){
            if(judge_Rectangle()&&judge_Diamond()){
                puts("Square");
            }
            else if(judge_Diamond()){
                puts("Diamond");
            }
            else if(judge_Rectangle()){
                puts("Rectangle");
            }
            else puts("Parallelogram");
        }
        else puts("Others");

    }
    return 0;
}

 

posted on 2016-07-15 16:01  Beserious  阅读(201)  评论(0编辑  收藏  举报