题目链接:

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. 并不对劲的CF1194E:Count The Rectangles

    题意 有\(n\)(\(n\leq 5000\))个平行于x轴或平行于y轴的线段.求这些线段围成了多少个长方形.由多个长方形拼成的也算. 题解 考虑暴力的做法:先分别计算每条横着的线与哪些竖着的线有交 ...

  2. Get HttpWebResponse and HttpClient Return String by proxy

    #region Get HttpClient Return String /// <summary> /// Get HttpClient Return String /// </s ...

  3. 怎样查看 MySQL 版本号

    1. 在命令行中直接查看版本号 mysql -V 2. 在 mysql --help 中查找与版本相关的信息 mysql --help | grep Ver 3. 在mysql命令行里面查看版本信息 ...

  4. IOC+EF+Core搭建项目框架(三)

    /// <summary> /// 表示类别映射配置 /// </summary> public partial class sys_UserMap : NopEntityTy ...

  5. WCF和SOA的简介

    1 什么是SOA:面向服务架构(service oriented architecture),他属于一种组件架构模式.SOA追求的是服务提供方和服务使用方的高度解耦. 服务必须是自解释的,也就是说必须 ...

  6. hadoop中hive的属性

    1.在hive中是可以删除文件的: hive> dfs -rm -R /u2.txt > ; Deleted /u2.txt 2.hive 中的default数据库 <propert ...

  7. 智能指针原理及实现(2)unique_ptr

    只允许基础指针的一个所有者. 可以移到新所有者(具有移动语义),但不会复制或共享(即我们无法得到指向同一个对象的两个unique_ptr). 替换已弃用的 auto_ptr. 相较于 boost::s ...

  8. 【转载】interpolation(插值)和 extrapolation(外推)的区别

    根据已有数据以及模型(函数)预测未知区域的函数值,预测的点在已有数据范围内就是interpolation(插值), 范围外就是extrapolation(外推). The Difference Bet ...

  9. linux安装vsftpd后无法登陆

    安装完成后在主机上登陆时,不管是输入用户,还是匿名都无法登陆 经过检查,发现是因为/etc/hosts.deny禁止了所有ip访问 将hosts.deny中的all:all删除,或者在/etc/hos ...

  10. CodeForcs 1169B Good Triple

    CodeForcs 1169B Good Triple 题目链接:http://codeforces.com/problemset/problem/1169/B 题目描述:给你m对不超过n的数字,找出 ...