Form a Square

题意就是 判断 给你四个点,能否组成一个正方形

要点:

格式很重要, 很重要!!!

数据很小,直接暴力

四个点判断是否为正方形,只需将所有可能的边长度算出来,然后选其中最短的边作为正方形的边长,进行比较,看有没有符合的四条边

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cmath>
  4. using namespace std;
  5. const int N = ;
  6. typedef struct aa{
  7. int x, y;
  8. }AA;
  9. AA a[N];
  10.  
  11. double dis(AA b, AA c)
  12. {
  13. double len = sqrt((b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y));
  14. return len;
  15. }
  16. int main()
  17. {
  18. int t, num, cnt = ;
  19. cin >> t;
  20. int T = t;
  21. while(T--)
  22. {
  23. for(int i = ; i < ; i++)
  24. {
  25. cin >> a[i].x >> a[i].y;
  26. }
  27. double ll = ;
  28. num = ;
  29. for(int i = ; i < ; i++)
  30. {
  31. for(int j = i+; j < ; j++)
  32. {
  33. double dist = dis(a[i], a[j]);
  34. if(dist == ll)
  35. {
  36. num++;
  37. }
  38. else if(dist < ll)
  39. {
  40. ll = dist;
  41. num = ;
  42. }
  43. }
  44. }
  45. if(num == )
  46. {
  47. if(cnt != t)
  48. cout << "Case " << "" << cnt++ << ":" << endl << "Yes" << endl << endl;
  49. else
  50. cout << "Case " << "" << cnt++ << ":" << endl << "Yes";
  51. }
  52. else
  53. {
  54. if(cnt != t)
  55. cout << "Case " << "" << cnt++ << ":" << endl << "No" << endl << endl;
  56. else
  57. cout << "Case " << "" << cnt++ << ":" << endl << "No";
  58. }
  59.  
  60. }
  61. return ;
  62. }

ZOJ2540 Form a Square的更多相关文章

  1. [LeetCode] Matchsticks to Square 火柴棍组成正方形

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  2. Leetcode: Matchsticks to Square && Grammar: reverse an primative array

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  3. HDU1518 Square(DFS,剪枝是关键呀)

    Square Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  4. Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告

    Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...

  5. HDU1518 Square(DFS)

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  6. HDOJ 1518 Square

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  7. Square

    Square TimeLimit: 1 Second   MemoryLimit: 32 Megabyte Totalsubmit: 1638   Accepted: 440 Description ...

  8. HDU-1518 Square(DFS)

    Square Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  9. Square(hdu 1511)

    题目描述: Problem Description Given a set of sticks of various lengths, is it possible to join them end- ...

随机推荐

  1. 马尔科夫随机场模型(MRF-Markov Random Field)

    原文: http://blog.sina.com.cn/s/blog_92c398b00102vs3q.html 马尔科夫过程​ 隐马尔科夫过程​​ 与马尔科夫相比,隐马尔可夫模型则是双重随机过程,不 ...

  2. 解决Ubuntu14.04 下 E: Encountered a section with no Package: header 问题

    参考: ubuntu-E:Encountered a section with no Package: header的解决办法 解决Ubuntu14.04 下 E: Encountered a sec ...

  3. zepto点透解决思路

    首先看几个链接, http://blog.youyo.name/archives/zepto-tap-click-through-research.html youyo的分析 http://softw ...

  4. React Native 之轮播图swiper组件

    注释:swiper组件是第三方组件 所以在使用之前应该先在命令行安装,然后将第三方的模块引入(第三方模块地址:https://github.com/leecade/react-native-swipe ...

  5. 关于Mybatis 的 Mapped Statements collection does not contain value for 异常 解决方案

    查看堆栈信息: at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:595) at org.apac ...

  6. Java中一种无意识的递归

    来自: Java编程思想P287 public class Main { /** * @param args */ @Override public String toString() { retur ...

  7. mybatis generator插件系列--lombok插件 (减少百分之九十bean代码)

    经常使用mybatis generator生成代码的你 有没有因为生成的getter/setter而烦恼呢? 有没有生成后又手动加toString/hashCode/Equals方法呢? 有没有改一个 ...

  8. python 集合的比较

    setx = set(["apple", "mango"]) sety = set(["mango", "orange" ...

  9. python 元组元素计数

    #create a tuple tuplex = , , , , , , , , print(tuplex) #return the number of times it appears in the ...

  10. linux 系统调用号表

    位于 /usr/include/asm/unistd.h 由于我是64位系统,所以有一些额外的东西.我的这个文件为下文 #ifndef _ASM_X86_UNISTD_H #define _ASM_X ...