LightOJ 1058 - Parallelogram Counting 几何思维
http://www.lightoj.com/volume_showproblem.php?problem=1058
题意:给你顶点,问能够成多少个平行四边形。
思路:开始想使用长度来扫描有多少根,但是好像坐标太大似乎不可行。其实我们可以通过找所有线段的中点的重合个数来计算有几个平行四边形,这种通过别的性质来判断几何关系的思维是解几何题的基础,当作入门?
/** @Date : 2016-12-02-21.49
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/ #include<bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e6+20; struct yuu
{
double x; double y;
bool operator == (const yuu &a) const
{
return (a.x == this->x) && (a.y == this->y);
}
}s[1010], t[N]; int cmp(yuu a, yuu b)
{
if(a.x != b.x)
return a.x > b.x;
return a.y > b.y;
}
map<pair<double, double> , int>q;
int main()
{ int T;
int cnt = 0;
cin >> T; while(T--)
{
q.clear();
int n;
scanf("%d", &n); for(int i = 1; i <= n; i++)
scanf("%lf%lf", &s[i].x, &s[i].y); int c = 0;
for(int i = 1; i <= n; i++)
{
for(int j = i + 1; j <= n; j++)
{
struct yuu p;
double x = 0, y = 0;
p.x = s[i].x + s[j].x;
p.y = s[i].y + s[j].y;
t[c++] = p;
//q[MP(x, y)]++;
}
}
sort(t, t + c, cmp);
LL ans = 0;
LL k = 0;
for(int i = 0; i < c; i++)
{
//cout << t[i].x << " " << t[i].y << endl;
if(t[i] == t[i + 1])
k++;
else
ans+=(k + 1) *k /2, k = 0;
}
//ans += (k + 1)* k / 2; /*for(auto i = q.begin(); i != q.end(); i++)
{
ans += (i->se)*(i->se - 1)/2;
}*/
/*map<pair<double, double>, int>::iterator it;
for(it = q.begin(); it != q.end(); it++)
ans += (it->se)*(it->se - 1) / 2;*/
printf("Case %d: %lld\n", ++cnt, ans); }
return 0; }
//判断对角线中点出现次数。
LightOJ 1058 - Parallelogram Counting 几何思维的更多相关文章
- LightOJ - 1058 - Parallelogram Counting(数学,计算几何)
链接: https://vjudge.net/problem/LightOJ-1058 题意: There are n distinct points in the plane, given by t ...
- 1058 - Parallelogram Counting 计算几何
1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...
- Light OJ - 1058 Parallelogram Counting(判定平行四边形)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- Parallelogram Counting(平行四边形个数,思维转化)
1058 - Parallelogram Counting PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...
- POJ 1971 Parallelogram Counting (Hash)
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 6895 Acc ...
- lightoj 1148 Mad Counting(数学水题)
lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...
- 计算几何 + 统计 --- Parallelogram Counting
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5749 Accepted: ...
- 几何+思维 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的两倍. ...
- LightOJ - 1148 - Mad Counting
先上题目: 1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 3 ...
随机推荐
- 2.azkaban3.0安装
安装规划安装azkban1.安装配置数据库2.下载安装web server3.安装mulit executor4.安装azkaban插件AZKABAN参数安装出现的问题 安装规划 IP 角色 端口 1 ...
- 安装HIVE
参考:https://cwiki.apache.org/confluence/display/Hive/GettingStarted 1.下载hive安装包 到apache官网或者其它地方下载 ...
- js实现滑动器效果
最近公司在做一个项目,页面中要用到滑动器效果,我的第一反应是使用HTML5 input类型中的range类型,但马上我就否定了这个想法,因为range类型存在浏览器的兼容性问题(在主流浏览器中).但又 ...
- LintCode-66.二叉树的前序遍历
二叉树的前序遍历 给出一棵二叉树,返回其节点值的前序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 返回 [1,2,3]. 挑战 你能使用非递归实现么? 标签 递归 二叉树 二叉树遍历 非递归 c ...
- iOS- 封装单例宏
在项目中,我们需要全局只有一个实例,节省不必要的内存,这时我们就需要使用里单例生成对象. 这时把单例的代码封装成宏,就能方便我们下次使用了. 在.h .m里直接导入头文件,调用 传入类名即可! sin ...
- 《C陷阱与缺陷》之1词法"陷阱"
编译器中负责将程序分解为一个一个符号的部分,一般称为"词法分析器".在C语言中,符号之间的空白(包括空格符.制表符或换行符)将被忽略. 1.=不同于== C语言使用符号" ...
- 异常--throw
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- perf中branch-filter到底是干嘛的?
./arch/x86/events/intel/core.c:2161: data.br_stack = &cpuc->lbr_stack;./arch/x86/e ...
- 如何实时获取DBGrid 中当前单元格输入的内容?
如何获取DBGrid 中当前单元格输入的内容? 还没输入完成,我想实时获取 Cell中的内容,以便作其他处理, 用什么事件呢? 所以Field的Onchange事件是没用的. 这个问题简单啊,每输入1 ...
- Delphi Code Editor 之 快捷菜单
Code Editor的快捷菜单分为两个部分:编辑器菜单项和调试器菜单项. 调试器菜单项留作以后讲解调试应用程序时再讲,这里只讲讲Code Editor的编辑器快捷菜单项. 下面列出了全部菜单项及描述 ...