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 解析(幾何)的更多相关文章

  1. Number of Parallelograms(求平行四边形个数)

    Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...

  2. D. Number of Parallelograms

    D. Number of Parallelograms 原题链接 time limit per test 4 seconds memory limit per test 256 megabytes Y ...

  3. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

  4. 【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 ...

  5. codeforces 660D D. Number of Parallelograms(计算几何)

    题目链接: D. Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes ...

  6. Number of Parallelograms CodeForces - 660D (几何)

    Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...

  7. Number() 与 parseInt()解析

    在 Python 中,将字符串转为整型变量的函数是 int() ,直接使用 int("123")就可以得到 123的输出结果,这样可以比较快速的得到我们想要的结果,在 js 中将 ...

  8. codeforce 660D Number of Parallelograms

    题意:询问多少个矩形. 统计横纵坐标差,放进vector中 #include<cstdio> #include<cstring> #include<iostream> ...

  9. CodeForces 660D Number of Parallelograms

    枚举两点,确定一条线段,计算每条线段的中点坐标. 按线段中点坐标排个序.找出每一种坐标有几个. 假设第x种坐标有y个,那么这些线段可以组成y*(y-1)/2种平行四边形. 累加即可. #include ...

随机推荐

  1. Spring Cloud各组件学习

    Spring-Cloud 介绍 SpringCloud各个组件详解,因为SpringCloud部分组件停止更新,故本项目包含原SpringCloud(基于SpringCloud H版和SpringBo ...

  2. spring-cloud-starter-openfeign 源码详细讲解

    1.测试环境搭建: 1.1 架构图: product服务提供一个接口: order服务通过feign的方式来调用product的接口: order服务需要引入依赖: <dependency> ...

  3. 深入了解Redis(6)-持久化原理

    Redis是一个内存数据库,数据保存在内存中.但我们都知道存储在内存中的数据会因为外部因素而丢失,所以Redis会把数据持久化到磁盘中,至于是如何持久化呢? 一.RDB 1.手动触发 save:该命令 ...

  4. Restful 风格是什么?

    1.1 什么是RESTful 1. REST与技术无关,代表的是一种软件架构风格(REST是Representational State Transfer的简称,中文翻译为"表征状态转移&q ...

  5. 0923 lca练习

    P1967 货车运输 题目描述 A 国有 nnn 座城市,编号从 11 1 到 n nn,城市之间有 mmm 条双向道路.每一条道路对车辆都有重量限制,简称限重. 现在有 qqq 辆货车在运输货物, ...

  6. 阿里云oss对象存储配置CDN

    阿里云oss对象存储配置CDN 1.打开阿里云CDN 2.填写信息,这个地方要注意,我的备案域名是www.ljwXXX.work,我们可以自定义一个域名,test.ljwXXX.work作为加速域名. ...

  7. Vue.js 学习笔记之三:与服务器的数据交互

    显而易见的,之前的02_toDoList存在着一个很致命的缺陷.那就是它的数据只存在于浏览器端,一但用户关闭或重新载入页面,他之前加入到程序中的数据就会全部丢失,一切又恢复到程序的初始状态.要想解决这 ...

  8. K8S环境的Jenkin性能问题处理续篇(任务Pod设置)

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos K8S环境的Jenkin性能问题处理 本文是<K ...

  9. tomcat:tomcat安装(在一台电脑上安装两个tomcat)

    1.安装前的说明 (1)在安装第二个tomcat之前,我们要知道安装一台tomcat的时候需要在电脑上添加两个系统变量 然后在path中配置: (2)这个时候我们就要思考了,当安装第二台服务器的时候首 ...

  10. 脚手架安装react

    //1 npm install -g create-react-app //2 create-react-app xxx //xxx项目名称 //3 cd xxx //xxx项目名称 npm star ...