高中数学

前面那一道数据小,可以暴力枚举每条直线是否相交。。这个显然不行。

两条直线平行,那么对应的直线方程 ax - by = c 的a和b一定比例是相同的,而且这个题只有整数坐标,所以最后只要是互相平行的直线,a和b一定可以化简成一样的。

所以我们把两点的直线用斜截式化简,可以求出a, b, c,然后除以gcd(a, b),就能把方程化成最简形式了。

最后拿当前的直线数-平行的直线数,就是与我们枚举到这条直线相交的直线数

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define full(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long ll;
inline int lowbit(int x){ return x & (-x); }
inline int read(){int X = 0, w = 0; char ch = 0;while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }while(isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();return w ? -X : X;
}
inline int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
template<typename T>
inline T max(T x, T y, T z){ return max(max(x, y), z); }
template<typename T>
inline T min(T x, T y, T z){ return min(min(x, y), z); }
template<typename A, typename B, typename C>
inline A fpow(A x, B p, C lyd){A ans = 1;for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;return ans;
}
const int N = 1005;
int x[N], y[N], n;
map<pair<int, int>, set<int>> m;
int main(){n = read();for(int i = 1; i <= n; i ++){x[i] = read(), y[i] = read();}ll cnt = 0, res = 0;for(int i = 1; i < n; i ++){for(int j = i + 1; j <= n; j ++){int x1 = x[i], y1 = y[i], x2 = x[j], y2 = y[j];int a = y1 - y2, b = x1 - x2, c = y1 * x2 - y2 * x1, f = gcd(a, b);a /= f, b /= f, c /= f;if(a < 0 || (a == 0 && b < 0)) a = -a, b = -b;pair<int, int> g = make_pair(a, b);//int c = a * x1 - b * y1;if(m[g].find(c) == m[g].end()){cnt ++;m[g].insert(c);res += cnt - m[g].size();}}}cout << res << endl;return 0;
}

转载于:https://www.cnblogs.com/onionQAQ/p/10845378.html

Codeforces Round #558 Div.2 - C2 - Power Transmission (Hard Edition)相关推荐

  1. Codeforces Round #568 (Div. 2)C2. Exam in BerSU (hard version)

    Codeforces Round #568 (Div. 2)C2. Exam in BerSU (hard version) 贪心+暴力 大致题意:N个人考试,每个人花费的时间是a[i],他们总共花费 ...

  2. Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)

    题目链接:http://codeforces.com/contest/1157/problem/C2 当左右两边数字相同时,需要判断一下取哪边能得到更长的递增序列 #include <iostr ...

  3. Codeforces Round #555 (Div. 3) c2 d e f

    c2:Increasing Subsequence (hard version) 那边小取那边,然后相等比较后面的长度 #include<bits/stdc++.h> using name ...

  4. 差分 ---- Codeforces Round #672 (Div. 2):C2. Pokémon Army (hard version)[差分的思想]

    题目链接 题目大意:就算给你一序列,按照顺序出若干个数组成一个的序列,然后对这个序列定义一个权值就算奇数位置的和减去偶数位置的和,问你能的到的最大的权值是多少? **a1 - a2 + a3 - a4 ...

  5. Codeforces Round #666 (Div. 2)B. Power Sequence(等比数列)

    problem 给出一个数列 两个操作 交换位置或者+1 -1 使数列成为首项为1的等比 求最少操作次数 solution 考虑到等比数列一定递增,直接排序 (过渡)试想特殊情况,排序后如果知道公比, ...

  6. Codeforces Round #672 (Div. 2) C2 - Pokémon Army (hard version)(贪心,维护变化值)

    x数组里选一个子数组y(原数组顺序),y1-y2+y3-y4+- 的最大值 然后还有q次交换操作,每次修改之后都要输出新的最大值 (1)如果没有修改,单纯对于当前数组考虑,我们最后选出来的点肯定是波峰 ...

  7. [Codeforces Round #162 (Div. 2)]A. Colorful Stones (Simplified Edition)

    地址:http://codeforces.com/contest/265/problem/A 昨晚没时间参赛 1 #include<stdio.h> 2 #include<strin ...

  8. Codeforces Round #162 (Div. 2) B. Roadside Trees (Simplified Edition)

    题目:http://codeforces.com/contest/265/problem/B #include <iostream> #include <stdio.h> #i ...

  9. Codeforces Round #774 (Div. 2)E题题解

    Codeforces Round #774 (Div. 2) E. Power Board 题目陈述 有一个n×m(1≤n,m≤106)n\times m(1\le n,m\le10^6)n×m(1≤ ...

  10. Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 最小生成树 + 虚拟点

    传送门 文章目录 题意: 思路: 题意: 思路: 看错题导致误入歧途,如果能早点看见翻译也不至于一天多也没想出来. 求联通的最小代价,自然的想到了能不能建边跑最小生成树. 对于两点之间比较好弄,直接n ...

最新文章

  1. Lync和Exchange 2013集成PART5:UCS和HD头像
  2. hadoop开发必读:认识Context类的作用
  3. 使用Python操作MySQL数据库
  4. 将阿里云上的nodejs应用配置成SAP云平台上destination的目的地之后
  5. 函数式编程 lambda表达式
  6. mysql 格林时间转换_格林时间转换成正常时间
  7. ICIP2012 关于Saliency Map的文章
  8. 软考高项历年作文真题
  9. 简单的自动化测试脚本
  10. 软件测试-面试题(基础+性能)
  11. js实现模拟自动点击按钮,并且在10秒倒计时之后疯狂点击
  12. 《穹顶之下》全文整理
  13. Pytorch模型通过paddlelite部署到嵌入式设备
  14. Ubuntu22.04.01Desktop桌面版安装记录221109
  15. 基于C++MFC的学生成绩管理系统
  16. YGG:2021年年终回顾
  17. 给div盒子设置背景图片
  18. 华子20221012笔试第三题
  19. 粉丝投稿 | Openvino2020.2.117在LattePanda上的安装和demo演示
  20. 轻巧易用,音质更进一步,南卡Lite pro 2真无线耳机上手

热门文章

  1. RabbitMQ消费者流量控制策略总结
  2. Vue 中的计算属性,方法,监听器
  3. EasyAndroid基础集成组件库之:EasyPhoto (单张)图片选择库
  4. 华为不同vlan单臂路由的配置
  5. 桌面支持--dcc打印机设置注意
  6. Matlab DIP(瓦)ch5图像复原练习
  7. Android查看每个线程CPU占用情况,以及工作内容分析
  8. oracle pls 00905,Oracle数据库存储过程出错了!大神帮忙看下什么问题!急急急!...
  9. matplotlib绘制李萨如图(三) 静态3D李萨如图
  10. LOJ2424「NOIP2015」子串