http://www.lightoj.com/volume_showproblem.php?problem=1058

题意:给你顶点,问能够成多少个平行四边形。

思路:开始想使用长度来扫描有多少根,但是好像坐标太大似乎不可行。其实我们可以通过找所有线段的中点的重合个数来计算有几个平行四边形,这种通过别的性质来判断几何关系的思维是解几何题的基础,当作入门?

  1. /** @Date : 2016-12-02-21.49
  2. * @Author : Lweleth (SoungEarlf@gmail.com)
  3. * @Link : https://github.com/
  4. * @Version :
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8. #define LL long long
  9. #define PII pair
  10. #define MP(x, y) make_pair((x),(y))
  11. #define fi first
  12. #define se second
  13. #define PB(x) push_back((x))
  14. #define MMG(x) memset((x), -1,sizeof(x))
  15. #define MMF(x) memset((x),0,sizeof(x))
  16. #define MMI(x) memset((x), INF, sizeof(x))
  17. using namespace std;
  18.  
  19. const int INF = 0x3f3f3f3f;
  20. const int N = 1e6+20;
  21.  
  22. struct yuu
  23. {
  24. double x; double y;
  25. bool operator == (const yuu &a) const
  26. {
  27. return (a.x == this->x) && (a.y == this->y);
  28. }
  29. }s[1010], t[N];
  30.  
  31. int cmp(yuu a, yuu b)
  32. {
  33. if(a.x != b.x)
  34. return a.x > b.x;
  35. return a.y > b.y;
  36. }
  37. map<pair<double, double> , int>q;
  38. int main()
  39. {
  40.  
  41. int T;
  42. int cnt = 0;
  43. cin >> T;
  44.  
  45. while(T--)
  46. {
  47. q.clear();
  48. int n;
  49. scanf("%d", &n);
  50.  
  51. for(int i = 1; i <= n; i++)
  52. scanf("%lf%lf", &s[i].x, &s[i].y);
  53.  
  54. int c = 0;
  55. for(int i = 1; i <= n; i++)
  56. {
  57. for(int j = i + 1; j <= n; j++)
  58. {
  59. struct yuu p;
  60. double x = 0, y = 0;
  61. p.x = s[i].x + s[j].x;
  62. p.y = s[i].y + s[j].y;
  63. t[c++] = p;
  64. //q[MP(x, y)]++;
  65. }
  66. }
  67. sort(t, t + c, cmp);
  68. LL ans = 0;
  69. LL k = 0;
  70. for(int i = 0; i < c; i++)
  71. {
  72. //cout << t[i].x << " " << t[i].y << endl;
  73. if(t[i] == t[i + 1])
  74. k++;
  75. else
  76. ans+=(k + 1) *k /2, k = 0;
  77. }
  78. //ans += (k + 1)* k / 2;
  79.  
  80. /*for(auto i = q.begin(); i != q.end(); i++)
  81. {
  82. ans += (i->se)*(i->se - 1)/2;
  83. }*/
  84. /*map<pair<double, double>, int>::iterator it;
  85. for(it = q.begin(); it != q.end(); it++)
  86. ans += (it->se)*(it->se - 1) / 2;*/
  87. printf("Case %d: %lld\n", ++cnt, ans);
  88.  
  89. }
  90. return 0;
  91.  
  92. }
  93. //判断对角线中点出现次数。

LightOJ 1058 - Parallelogram Counting 几何思维的更多相关文章

  1. LightOJ - 1058 - Parallelogram Counting(数学,计算几何)

    链接: https://vjudge.net/problem/LightOJ-1058 题意: There are n distinct points in the plane, given by t ...

  2. 1058 - Parallelogram Counting 计算几何

    1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...

  3. Light OJ - 1058 Parallelogram Counting(判定平行四边形)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  4. Parallelogram Counting(平行四边形个数,思维转化)

    1058 - Parallelogram Counting    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...

  5. POJ 1971 Parallelogram Counting (Hash)

          Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6895   Acc ...

  6. lightoj 1148 Mad Counting(数学水题)

    lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...

  7. 计算几何 + 统计 --- Parallelogram Counting

    Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5749   Accepted: ...

  8. 几何+思维 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest K. Revenge of the Dragon

    题目链接:http://codeforces.com/gym/101149/problem/K 题目大意: 给你两个点a,b.一个人在a点,一个人在b点,b点的人要追杀a的点,他的跑步速度是a的两倍. ...

  9. LightOJ - 1148 - Mad Counting

    先上题目: 1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 3 ...

随机推荐

  1. Thunder团队第六周 - Scrum会议3

    Scrum会议3 小组名称:Thunder 项目名称:i阅app Scrum Master:李传康 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...

  2. Thunder团队贡献分分配规则

    规则1:基础分,拿出总分的40%进行均分. 规则2:参与会议者,每人次加0.5分. 规则3:积极贡献者,通过团队投票,半数及以上同意,每次加0.5分. 规则4:根据项目完成情况,核实每个人的工作量,投 ...

  3. 算法与数据结构3.3 calculator

    ★实验任务 小 V 发明了一个神奇的整数计算器: 给定一个合法的表达式,这个计算器能求出这个表达式的最终答案. 表达式可能包含: +:运算符,整数加法.如 1+1=2 -:运算符,整数减法.如 1-1 ...

  4. 什么是Processing

    Processing是一种计算机语言,以JAVA语法为基础,可转化成JAVA程序,不过在语法上简易许多.所有的原始代码及开发环境开放,主要用于艺术.影像.影音的设计与处理. 其次为什么要介绍这款软件呢 ...

  5. OSG学习:自动对齐节点示例

    /********************************************************** *Write by FlySky *zzuxp@163.com http://w ...

  6. 面试:谈谈你对jQuery的理解

    jQuery是一个轻量级的javascript框架,极大的简化了js的编程. 1.首先jQuery提供了强大的元素选择器.用于获取html页面中封装了html元素的jQuery对象.像常见的选择器有: ...

  7. Winform程序部署方式总结一——ClickOnce发布

    针对Winform程序,介绍两种常用打包方式:ClickOnce和Windows Installer 应用程序如下: 一.ClickOnce发布 1.找到需要发布的项目文件,右击,从弹出的快捷菜单中找 ...

  8. Apache与Tomcat负载均衡

    Apache HTTP Server 与 Tomcat 的三种连接方式JK,http_proxy,ajp_proxy.下面逐个介绍一下(本篇介绍的示例都是基于前面介绍的已经搭建好的Tomcat集群,都 ...

  9. 【Python】Python中的下划线

    单下划线(如: _var): 使用单下划线,用于指定该名变量或函数属性为“私有”.这仅仅是一个惯例,不是强制规定.用于向其他程序员表明这个变量或函数仅仅供内部使用,外部不要访问它.但实际上外部还是可以 ...

  10. Java调用WebService之Axis实现

    import org.apache.axis.client.Call; import org.apache.axis.client.Service; /** * @ClassName: TestAxi ...