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.判断是否菱形,是否长方形,都是则为正方形,都不是则为平行四边形,其一是另一否,则是菱形或长方形。

 #include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; int T, x[], y[]; bool Parallelogram()
{
int a = (y[] - y[]) * (x[] - x[]);
int b = (x[] - x[]) * (y[] - y[]);
if(a != b) return false;
a = (x[] - x[]) * (y[] - y[]);
b = (x[] - x[]) * (y[] - y[]);
return a == b;
} bool Rectangle()
{
int a = (x[] - x[]) * (x[] - x[]) + (y[] - y[]) * (y[] - y[]);
int b = (x[] - x[]) * (x[] - x[]) + (y[] - y[]) * (y[] - y[]);
return a == b;
} bool Diamond()
{
int a = (y[] - y[]) * (y[] - y[]);
int b = (x[] - x[]) * (x[] - x[]);
return a == -b;
} int main()
{
scanf("%d", &T);
for(int ca = ; ca <= T; ca++)
{
int i, j;
for(i = ; i < ; i++)
{
scanf("%d %d", &x[i], &y[i]);
}
printf("Case #%d: ", ca);
for(i = ; i < ; i++)
{
for(j = i + ; j < ; j++)
{
if(x[i] == x[j] && y[i] == y[j])
break;
}
if(j != ) break;
}
if(i != ) puts("Others");
else
{
bool tag, tag1;
tag = Parallelogram();
if(tag == false) {puts("Others");}
else
{
tag = Rectangle();
tag1 = Diamond();
if(tag == false && tag1 == false) puts("Parallelogram");
else if(tag == true && tag1 == true) puts("Square");
else if(tag == true) puts("Rectangle");
else if(tag1 == true) puts("Diamond");
}
}
}
return ;
}

最新文章

  1. C语言学习021:管道
  2. Markdown 语法说明
  3. UI设计的分类
  4. 第十二篇 SQL Server代理多服务器管理
  5. elementoryOS / ubuntu U盘启动问题的解决
  6. 【WP之一】]独立存储
  7. Simple Worker Thread Class
  8. DVDRW光驱无法读DVD刻录盘
  9. Linq XML
  10. PAT (Basic Level) 1001害死人不偿命的(3n+1)猜想 (15)
  11. Unity3D学习笔记-------小地图制作
  12. ASP.Net连接WebServer使用Https协议(证书)
  13. webservice一片:其中在外线呼叫数据,查看返回数据
  14. 【原创】Windows平台下Git的安装与配置
  15. TopSnackbar,在顶部滑出显示的Snackbar;
  16. pycharm无法使用ctrl+c/v复制粘贴的问题
  17. C - 继续畅通工程 最小生成树
  18. iOS学习笔记之Reachability简单使用
  19. 从零开始搭建webpack+react开发环境
  20. docker+selenium Grid搭建自动化分布式测试环境

热门文章

  1. Access连接数据源配置(新手必知)
  2. SpringBoot与Swagger2整合
  3. ArrayList和LinkedList源码分析
  4. Hash(散列函数)简单应用引出解决散列冲突的四种方法
  5. 对scrum站立会议的理解
  6. alpha发布评论
  7. django amdin页面下拉列表的外键增加条件过滤
  8. p2 钢体
  9. 20个PHP程序性能优化的方法
  10. hdu-题目:1058 Humble Numbes