题目链接:

https://codeforces.com/contest/1163/problem/C2

题意:

给出$n$个点,任意两点连接一条直线,求相交直线的对数

数据范围:

$1 \le n \le 10^3$

分析:

先建立所有的直线,可以把直线定义成$ax+ by=c$,但是需要把$a$和$b$的大小化简成最小,保证直线的唯一性

$k=\frac{y_{1}-y_{2}}{x_{1}-x_{2}}$,上下化简,再用点斜式构造$ax+ by=c$

ac代码:

#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
using namespace std;
const int maxn=1000+10;
struct Point
{
int x,y;
}point[maxn];
map< pa,set<int> >ma;
int n;
int main ()
{
int cnt=0;
ll ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d %d",&point[i].x,&point[i].y);
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
int x1=point[i].x,y1=point[i].y;
int x2=point[j].x,y2=point[j].y;
int a=(y1-y2),b=(x2-x1),c=(x2-x1)*y1+x1*(y1-y2);
int f=__gcd(a,b);
a/=f,b/=f,c/=f;
if(a<0||(a==0&&b<0))a=-a,b=-b,c=-c;
pa now=make_pair(a,b);
if(ma[now].find(c)==ma[now].end())
{
cnt++;
ma[now].insert(c);
ans+=cnt-(int)ma[now].size();
}
}
}
printf("%lld\n",ans);
return 0;
}

  

codeforces#1163C2. Power Transmission (Hard Edition)(计算几何)的更多相关文章

  1. C2. Power Transmission (Hard Edition) 解析(思維、幾何)

    Codeforce 1163 C2. Power Transmission (Hard Edition) 解析(思維.幾何) 今天我們來看看CF1163C2 題目連結 題目 給一堆點,每兩個點會造成一 ...

  2. C2. Power Transmission (Hard Edition)(线段相交)

    This problem is same as the previous one, but has larger constraints. It was a Sunday morning when t ...

  3. light oj 1155 - Power Transmission【拆点网络流】

    1155 - Power Transmission   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  4. uva 10330 - Power Transmission(网络流)

    uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...

  5. [CodeForces - 1225D]Power Products 【数论】 【分解质因数】

    [CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...

  6. [Codeforces 1246B] Power Products (STL+分解质因数)

    [Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...

  7. CodeForces - 906D Power Tower(欧拉降幂定理)

    Power Tower CodeForces - 906D 题目大意:有N个数字,然后给你q个区间,要你求每一个区间中所有的数字从左到右依次垒起来的次方的幂对m取模之后的数字是多少. 用到一个新知识, ...

  8. [Codeforces]906D Power Tower

    虽说是一道裸题,但还是让小C学到了一点姿势的. Description 给定一个长度为n的数组w,模数m和询问次数q,每次询问给定l,r,求: 对m取模的值. Input 第一行两个整数n,m,表示数 ...

  9. Codeforces 1120D Power Tree [最小生成树]

    洛谷 Codeforces 这题怎么一个中文题解都没有,是不是你们都认为太水了-- 思路 显然可以用dfs序把每个节点变成给一个区间的叶子节点加上某个数. 显然把叶子序列差分一下变为\(a_1,a_2 ...

随机推荐

  1. 使用Harbor搭建Docker私有仓库

    ip:192.168.0.145 环境设置 防火墙,selinux等,可以使用本章开头的那个shell脚本 其他主机的hosts文件也都添加上 ip hub.aaa.com windows系统的hos ...

  2. DataTime.Now.Ticks

    getTime public long getTime() 返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数. 返回: 自 1970 年 1 月 1 ...

  3. Ocelot + Consul的demo

    参考大佬的博客写的:https://www.cnblogs.com/alan-lin/p/9126155.html:也可以参考这篇博客:https://www.cnblogs.com/axzxs200 ...

  4. C#UDP异步通信

    using SetingDemo.LogHelp;using SetingDemo.SingleRowDeclare;using System;using System.Collections.Gen ...

  5. JDK + Tomcat 安装 + 制作自定义镜像【第 3 篇 系统镜像】

    [第 1 篇 JDK]:https://www.cnblogs.com/del88/p/11842387.html[第 2 篇 Tomcat]:https://www.cnblogs.com/del8 ...

  6. Js-带进度条的轮播图

    带进度条的轮播图--原生JS实现 实现了图片自动轮播,左右按钮实现图片左右转换,下方原点或者缩小图点击选择其中的某一张图片,然后有红条实现图片的进度. <div class="cont ...

  7. 第二章、drf框架 - 请求模块 | 渲染模块 解析模块 | 异常模块 | 响应模块 (详细版)

    目录 drf框架 - 请求模块 | 渲染模块 解析模块 | 异常模块 | 响应模块 Postman接口工具 drf框架 注册rest_framework drf框架风格 drf请求生命周期 请求模块 ...

  8. com.android.ddmlib.adbcommandrejectedexception:未经授权的设备。

    出现这种问题的原因是adb被杀死了,根据网上的说法在platform-tools下双击adb.exe 也启动不了. 在命令提示符中执行    adb kill-server adb start-ser ...

  9. mysql启动失败,unit not found

    1 mysql启动 Failed to start mysqld.service: Unit not found.   2 查询/etc/init.d/下是否存在mysqld ll /etc/init ...

  10. (备忘)Linux mount(挂载命令)详解

    挂接命令(mount) 首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用到的. 命令格式:mount [-t vfstype] [-o option ...