由于斜率的储存精度不够,所以使用最简分数表示记录。

合并同一个位置上的点,然后统计个数,利用公式先求出至少包含2个点的数量。

然后再是求某位之上的点与某一斜率的个数,那就是每边至少一个点的个数相乘。

#include<bits/stdc++.h>
using namespace std; const int maxn = ;
const long long mod = 1e9 + ;
long long powtwo[maxn];
map<pair<int, int>, int>mp; struct node{
int x, y, cnt;
bool operator<(const node &a)const{
if(x == a.x) return y < a.y;
else return x < a.x;
}
}a[maxn]; int main(){
powtwo[] = ;
for(int i = ; i < maxn; i ++) powtwo[i] = powtwo[i - ] * % mod; int T, n;scanf("%d",&T);while(T --){
scanf("%d",&n);
for(int i = ; i < n; i ++)
scanf("%d%d",&a[i].x, &a[i].y);
sort(a, a + n);
int i, j, cnt = ;
for(i = ; i < n;){
for(j = i + ; j < n; j ++)
if((a[i].x != a[j].x) || (a[i].y != a[j].y))
break; a[cnt].x = a[i].x;
a[cnt].y = a[i].y;
a[cnt ++].cnt = j - i;
i = j;
} long long ans = 0LL;
for(i = ; i < cnt; i ++)
ans = (ans + ((a[i].cnt > ) ? powtwo[a[i].cnt] - - a[i].cnt : )) % mod; for(i = ; i < cnt; i ++){
mp.clear();
for(j = i + ; j < cnt; j ++){
int x = a[j].x - a[i].x;
int y = a[j].y - a[i].y;
int gcd = __gcd(x, y);
if(gcd){
x /= gcd; y /= gcd;
}
mp[make_pair(x, y)] += a[j].cnt;
}
for(auto it : mp){
ans += (powtwo[a[i].cnt] - ) * (powtwo[it.second] - );
ans %= mod;
}
}
printf("%lld\n",ans);
}
return ;
}

Eureka (数学组合 + 斜率)的更多相关文章

  1. [BZOJ5305] [HAOI2018] 苹果树 数学 组合计数

    Summary 题意很清楚: 小 \(C\) 在自己家的花园里种了一棵苹果树, 树上每个结点都有恰好两个分支. 经过细心的观察, 小 \(C\) 发现每一天这棵树都会生长出一个新的结点. 第一天的时候 ...

  2. UVA11538 - Chess Queen(数学组合)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. Codeforces 626D Jerry's Protest 「数学组合」「数学概率」

    题意: 一个袋子里装了n个球,每个球都有编号.甲乙二人从每次随机得从袋子里不放回的取出一个球,如果甲取出的球比乙取出的球编号大则甲胜,否则乙胜.保证球的编号xi各不相同.每轮比赛完了之后把取出的两球放 ...

  4. 数学(组合,容斥):COGS 1220. 盒子与球

    1220. 盒子与球 ★   输入文件:boxball.in   输出文件:boxball.out   简单对比 时间限制:1 s   内存限制:128 MB [问题描述] 现有r个互不相同的盒子和n ...

  5. HDU 6425 Rikka with Badminton(组合问题签到)题解

    题意:问你有多少种选法使得不能满足大于等于2个拍子且大于等于1个球. 思路:数学组合问题,分类讨论一下,刚开始的时候分的很乱,写的乱七八糟的...还有注意MOD,基本上有大数相乘的地方都要先MOD一下 ...

  6. kaggle数据挖掘竞赛初步--Titanic<随机森林&特征重要性>

    完整代码: https://github.com/cindycindyhi/kaggle-Titanic 特征工程系列: Titanic系列之原始数据分析和数据处理 Titanic系列之数据变换 Ti ...

  7. Spark的Straggler深入学习(2):思考Block和Partition的划分问题——以论文为参考

    一.partition的划分问题 如何划分partition对block数据的收集有很大影响.如果需要根据block来加速task的执行,partition应该满足什么条件? 参考思路1:range ...

  8. spoj 78

    数学  组合 隔板法 #include <iostream> #include <cstring> #include <cstdio> #include <s ...

  9. 可视化n次贝塞尔曲线及过程动画演示--大宝剑

    起因 研究css中提供了2次.3次bezier,但是没有对n次bezier实现.对n次的实现有很大兴趣,所以就用js的canvas搞一下,顺便把过程动画模拟了一下. 投入真实生产之中,偏少. n次be ...

随机推荐

  1. LeetCode 349 Intersection of Two Arrays 解题报告

    题目要求 Given two arrays, write a function to compute their intersection. 题目分析及思路 给定两个数组,要求得到它们之中共同拥有的元 ...

  2. LeetCode 461 Hamming Distance 解题报告

    题目要求 The Hamming distance between two integers is the number of positions at which the corresponding ...

  3. Java 堆外内存

    入口ByteBuffer.allocateDirect public static ByteBuffer allocateDirect(int capacity) { return new Direc ...

  4. C++的类大小

    有以下C++类 #pragma pack(push) #pragma pack(1) class task /*:public OSThread*/{ //public: // void Entry( ...

  5. [MySQL优化1]centos中MySQL列出所有表

    步骤1 - 连接到MySQL数据库服务器:[root@host]# mysql -u root -pEnter password:******提示登陆成功Welcome to the MySQL mo ...

  6. 显示日期的指令: date

    1.显示日期的指令: date (1)参数: (2)实例

  7. c# 文件或者文件夹改名的最简单方法

    使用cmd命令 ren Process.Start( "cmd", "/C " + "ren f:\\first c code.txt zhou.tx ...

  8. VGA线 1080P之伤 <中秋节篇>

    故障:通过一台笔记本,在一台高清的电视机上使用VGA线进行视频传输,分辩率最高只能显示1600*1200,为什么不是1080P? 哎,我也很郁闷,查了相关的资料~电视机是最高支持1080P分辩率的,笔 ...

  9. axios的使用

    一.首先要安装axios npm install axios 使用: -先在main中配置: import axios from 'axios' //要把axios放进一个全局变量中 //把axios ...

  10. strncat、strcat

    strncat函数 2007年03月15日 20:32:00 阅读数:13676 函数原型:extern char *strncat(char *dest,char *src,int n) 参数说明: ...