D. Number of Parallelograms 解析(幾何)
Codeforce 660 D. Number of Parallelograms 解析(幾何)
今天我們來看看CF660D
題目連結
題目
給你一些點,求有多少個平行四邊形。
前言

想法
注意到,只要有兩個等長的平行邊,那我們就找到了一個平行四邊形了。
所以只要用一個\(map\)紀錄每個線段出現的次數,且每次加入一個線段(我們枚舉線段)時,先把答案加上目前有多少等長平行線段,最後答案除以二就行了。
程式碼:
const int _n=2010;
int t,n,x,y;
vector<PII> ps;
map<PII,int> cnt;
ll ans;
main(void) {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;rep(i,0,n){cin>>x>>y;ps.pb({x,y});}
rep(i,0,n-1)rep(j,i+1,n){
PII v={ps[j].fi-ps[i].fi,ps[j].se-ps[i].se};
if(v.fi<0)v.fi=-v.fi,v.se=-v.se;
if(v.fi==0 and v.se<0)v.se=-v.se;
ans+=cnt[v]; cnt[v]++;
}cout<<ans/2<<'\n';
return 0;
}
標頭、模板請點Submission看
Submission
D. Number of Parallelograms 解析(幾何)的更多相关文章
- Number of Parallelograms(求平行四边形个数)
Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
- D. Number of Parallelograms
D. Number of Parallelograms 原题链接 time limit per test 4 seconds memory limit per test 256 megabytes Y ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- 【CodeForces 660D】Number of Parallelograms(n个点所能组成的最多平行四边形数量)
You are given n points on a plane. All the points are distinct and no three of them lie on the same ...
- codeforces 660D D. Number of Parallelograms(计算几何)
题目链接: D. Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes ...
- Number of Parallelograms CodeForces - 660D (几何)
Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...
- Number() 与 parseInt()解析
在 Python 中,将字符串转为整型变量的函数是 int() ,直接使用 int("123")就可以得到 123的输出结果,这样可以比较快速的得到我们想要的结果,在 js 中将 ...
- codeforce 660D Number of Parallelograms
题意:询问多少个矩形. 统计横纵坐标差,放进vector中 #include<cstdio> #include<cstring> #include<iostream> ...
- CodeForces 660D Number of Parallelograms
枚举两点,确定一条线段,计算每条线段的中点坐标. 按线段中点坐标排个序.找出每一种坐标有几个. 假设第x种坐标有y个,那么这些线段可以组成y*(y-1)/2种平行四边形. 累加即可. #include ...
随机推荐
- Ribbon自定义负载均衡策略,在网关实现类似Ip_hash的负载均衡,ribbon给单个服务配置属性
背景: 我需要在网关实现一种功能,某个用户的请求永远打在后台指定的服务,也就是根据ip地址进行负载均衡 原理: 在ribbon的配置类下: 那我们自己创建一个IRule的实现类,模仿ZoneAvoid ...
- Go 分支流程
if/else 基本使用 if/else应该是每个编程语言中都具备的基本分支结构. 需要注意的是if||else与{要放在同一行上,否则会抛出异常. 另外,当多个else if出现时,不同分支只会执行 ...
- 使用SSM框架实现图片的上传
SSM实现图片上传功能 效果 在前端页面点击上传图片功能按钮,即弹出文件管理器,选择图片并上传: 思路 在前端页面添加 input 标签,type选择file. 在后端controller编写方法. ...
- 03 sublime text3下配置Java的编译运行环境
参考如下文章,加入了自己的干货: https://blog.csdn.net/qq_38295511/article/details/81140069 https://blog.csdn.net/qq ...
- matlab中strcmpi比较字符串(不区分大小写)
来源:https://ww2.mathworks.cn/help/matlab/ref/strcmpi.html?searchHighlight=strcmpi&s_tid=doc_srcht ...
- 手把手教你AspNetCore WebApi:数据验证
前言 小明最近又遇到麻烦了,小红希望对接接口传送的数据进行验证,既然是小红要求,那小明说什么都得满足呀,这还不简单嘛. 传统验证 [HttpPost] public async Task<Act ...
- 利用 JS 脚本实现网页全自动秒杀抢购
利用 JS 脚本实现网页全自动秒杀抢购 倒计时页面: 倒计时未结束时,购买按钮还不能点击. 结束时,可以点击购买,点击后出现提示"付款成功" 展示效果 1.制作测试网页 首先我们来 ...
- C# Socket TCP发送图片与接收图片
如果需要查看更多文章,请微信搜索公众号 csharp编程大全,需要进C#交流群群请加微信z438679770,备注进群, 我邀请你进群! ! ! --------------------------- ...
- mycat 单库分表实践
参考 https://blog.csdn.net/sq2006hjp/article/details/78732227 Mycat采用的水平拆分,不管是分库还是分表,都是水平拆分的.分库是指,把一个大 ...
- Java安全之Javassist动态编程
Java安全之Javassist动态编程 0x00 前言 在调试CC2链前先来填补知识盲区,先来了解一下Javassist具体的作用.在CC2链会用到Javassist以及PriorityQueue来 ...