题目链接:https://codeforces.com/contest/1036/problem/E

思路:学会了一个在线段上的整数点等于 GCD(x1 - x2, y1 - y2) +  1,然后去重线段相交的重复整点。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-;
const int maxn = 1e3 + ;
int sgn(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
struct Point{
double x, y;
Point(){}
Point(double _x, double _y){
x = _x, y = _y;
}
void input(){
scanf("%lf%lf", &x, &y);
}
bool operator == (Point b) const{
return sgn(x - b.x) == && sgn(y - b.y) == ;
}
bool operator < (Point b)const{
return sgn(x - b.x) == ? sgn(y - b.y < ) : x < b.x;
}
Point operator - (const Point &b)const{
return Point(x - b.x, y - b.y);
}
double operator ^(const Point &b){
return x * b.y - y * b.x;
}
double operator *(const Point &b){
return x * b.x + y * b.y;
}
};
struct Line{
Point s, e;
Line(){}
Line(Point _s, Point _e){s = _s, e = _e;}
bool operator == (Line v){
return (s == v.s) && (e == v.e);
}
void input(){
s.input();
e.input();
}
int segcrossing(Line v)
{
int d1 = sgn((e - s)^(v.s - s));
int d2 = sgn((e - s)^(v.e - s));
int d3 = sgn((v.e - v.s)^(s - v.s));
int d4 = sgn((v.e - v.s)^(e - v.s));
if( (d1^d2) == - && (d3^d4) == - )return ;
return (d1 == && sgn((v.s - s)*(v.s - e)) <= ) ||
(d2 == && sgn((v.e - s)*(v.e - e)) <= ) ||
(d3 == && sgn((s - v.s)*(s - v.e))<=) ||
(d4 == && sgn((e - v.s)*(e - v.e))<=);
}
Point crosspoint(Line v){
double a1 = (v.e - v.s)^(s - v.s);
double a2 = (v.e - v.s)^(e - v.s);
return Point((s.x*a2 - e.x*a1)/(a2 - a1),(s.y*a2 - e.y*a1)/(a2 - a1));
}
};
Line l[maxn];
int main()
{
std::ios::sync_with_stdio(false);
int n;
cin >> n;
ll ans = ;
int x1, x2, y1, y2;
for(int i = ;i < n;i++){
cin >> x1 >> y1 >> x2 >> y2;
l[i] = Line(Point((double)x1, (double)y1), Point((double)x2, (double)y2));
ans += __gcd(abs(x1 - x2), abs(y1 - y2)) + ;
}
for(int i = ;i < n;i++)
{
set< pair<int, int> >st;
for(int j = i + ;j < n;j++)
{
if(l[i].segcrossing(l[j])){
Point v = l[i].crosspoint(l[j]);
if((int)v.x == v.x && (int)v.y == v.y)
st.insert({v.x,v.y});
}
}
ans -= st.size();
}
cout << ans << endl;
return ;
}

E. Covered Points (线段上的整点数)的更多相关文章

  1. Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】

    <题目链接> <转载于 >>>  > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...

  2. EDU 50 E. Covered Points 利用克莱姆法则计算线段交点

    E. Covered Points 利用克莱姆法则计算线段交点.n^2枚举,最后把个数开方,从ans中减去. ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算. #include ...

  3. POJ 1265 /// 皮克定理+多边形边上整点数+多边形面积

    题目大意: 默认从零点开始 给定n次x y上的移动距离 组成一个n边形(可能为凹多边形) 输出其 内部整点数 边上整点数 面积 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 ...

  4. BZOJ 1041: [HAOI2008]圆上的整点

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3621  Solved: 1605[Submit][Sta ...

  5. BZOJ 1041: [HAOI2008]圆上的整点【数论,解方程】

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4210  Solved: 1908[Submit][Sta ...

  6. [ HAOI 2008 ] 圆上的整点

    \(\\\) Description 给出一个整数 \(r\) ,求圆 \(x^2+y^2=r^2\) 上的整点数. \(r\le 2\times 10^9\) \(\\\) Solution 神题. ...

  7. Covered Points Count CF1000C 思维 前缀和 贪心

     Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

  8. C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)

    C - Covered Points Count CodeForces - 1000C You are given nn segments on a coordinate line; each end ...

  9. 「Luogu P2508」[HAOI2008]圆上的整点 解题报告

    题面 给定圆的半径,求圆上整点数 这是一道很Nice的数学题!超爱!好吧,由于这道题,我去Study了一下复数(complex number)复杂的数 真棒!!! 有兴趣的戳这里!!!\(\huge ...

随机推荐

  1. Iconv作用以及安装问题解决

    当我们在使用Window操作系统的时候,可能使用最多的文本格式就是txt了,但是当我们将Window平台下的txt文本文档拷贝到Linux平台下查看时,发现原来的中文全部变成了乱码.没错, 引起这个结 ...

  2. 用threading 解决 gunicorn worker timeout

    产生worker timeout 的背景 while 1: ..... time.sleep(1) gunicorn运行起来,只等待了30s,就卡住了,没报任何异常或err,查了gunicorn 官方 ...

  3. VS2017/VS2019 git Authentication failed for "XXXXXXXXXx"

    解决办法: 控制面板,凭证管理==>删掉 对应代码仓库地址的凭证.删掉,是删掉.因为我更新了还是没有用.

  4. 用css3写出的倒三角形

    <!DOCTYPE html><html><head><meta charset="gb2312" /><title>无 ...

  5. intellij中maven不能导入pom文件中指定的jar包

    pom文件配置依赖的jar包版本,可以有默认的版本,如下 <profiles> <profile> <id>default_version</id> & ...

  6. SSOJ 317 Fast Ride

    317. Fast Ride Time limit per test: 0.25  second(s) Memory limit: 65536 kilobytes input: standard ou ...

  7. java面试题-看到那记录到哪

    哈希冲突 如果两个不同的元素,通过哈希函数得到的实际存储地址相同怎么办?也就是说,当我们对某个元素进行哈希运算,得到一个存储地址,然后要进行插入的时候,发现已经被其他元素占用了,其实这就是所谓的哈希冲 ...

  8. 初始 vue

    1.js,jQuery编程范式:命令式编程 vue编程范式:声明式编程 v-for   遍历数组内容 v-on: click   监听点击事件,语法糖 @click el: 类型:string | H ...

  9. elasticsearch Java Client用户指南

    这里使用的Java客户端版本是5.1.2,Elasticsearch的版本号也要是5.1.2,否则一些功能可能不支持. 之前介绍过Spring Data Elasticsearch,那里也是使用了本文 ...

  10. Pandas之loc\iloc\ix

    ---------------------------------------------------------------------------------------------------- ...