题意:

    在二维平面上给出n条不共线的线段,问这些线段总共覆盖到了多少个整数点

  

  解法:

      用GCD可求得一条线段覆盖了多少整数点,然后暴力枚举线段,求交点,对于相应的

    整数交点,结果-1即可

  

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define eps 1e-6
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
typedef pair<int,int> pii;
const long long linf=1LL<<;
const int iinf=<<;
const double dinf=1e17;
const int Mod=1e9+;
typedef long long ll;
typedef long double ld;
const int maxn=;
int n;
struct Point{
ll x,y;
int id;
Point(ll x=,ll y=):x(x),y(y) {}
Point operator - (const Point &a)const { return Point(x-a.x,y-a.y);}
bool operator == (const Point &a)const { return x==a.x && y==a.y; }
};
ll Cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
}
ll Dot(Vector a,Vector b) {
return a.x*b.x+a.y*b.y;
}
bool onsg(Point p,Point a1,Point a2){
return Cross(a1-p,a2-p)== && Dot(a1-p,a2-p)<;
}
void ck(ll &c){
if(c>) c=;
else if(c<) c=-;
}
int Ins(Point a1,Point a2,Point b1,Point b2){
if(a1==b1 || a1==b2 || a2==b1 || a2==b2) return ;
if(onsg(a1,b1,b2) || onsg(a2,b1,b2) || onsg(b1,a1,a2) || onsg(b2,a1,a2)) return ;
ll c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1);
ll c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
ck(c1);ck(c2);ck(c3);ck(c4);
return c1*c2< && c3*c4<;
}
set<pair<ll,ll> >c;
void chk(Point p,Vector v,Point q,Vector w){
Vector u=p-q;
ll v1=Cross(w,u),v2=Cross(v,w);
if(abs(v1*v.x)%v2!= || abs(v1*v.y)%v2!=) return ;
ll xx,yy;
xx=p.x+v.x*v1/v2;yy=p.y+v.y*v1/v2;
c.insert(mkp(xx,yy));
}
struct segm{
Point p1,p2;
};
segm ss[maxn];
Point p1,p2;
void solve(){
iossy;
cin>>n;
int ans=;
For(i,,n){
cin>>p1.x>>p1.y>>p2.x>>p2.y;
ss[i].p1=p1;ss[i].p2=p2;
ans+=__gcd(abs(ss[i].p2.x-ss[i].p1.x),abs(ss[i].p2.y-ss[i].p1.y))+;
}
For(i,,n){
c.clear();
For(j,i+,n){
int ct=Ins(ss[i].p1,ss[i].p2,ss[j].p1,ss[j].p2);
if(ct) chk(ss[i].p1,ss[i].p2-ss[i].p1,ss[j].p1,ss[j].p2-ss[j].p1);
}
ans-=c.sz;
}
//cout<<ans-c.sz<<endl;
cout<<ans<<endl;
}
int main(){
int t=;
// For(i,1,t) printf("Case #%d: ",i);
solve();
return ;
}

[CodeForces-1036E] Covered Points 暴力 GCD 求交点的更多相关文章

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

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

  2. Codeforces 1036E. Covered Points

    又一次写起了几何.... 特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个set里,对每一个set,每次删除set.size()即可 重点在于判断两条线 ...

  3. CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)

    https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖 ...

  4. codeforces 1000C - Covered Points Count 【差分】

    题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...

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

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

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

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

  7. Educational Codeforces Round 46 C - Covered Points Count

    C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...

  8. 个人项目作业$\cdot$求交点个数

    个人项目作业\(\cdot\)求交点个数 一.作业要求简介 本次作业是北航计算机学院软件工程课程的个人项目作业,个人开发能力对于软件开发团队是至关重要的,本项目旨在通过一个求几何图形的交点的需求来使学 ...

  9. POJ 1039 Pipe(直线和线段相交判断,求交点)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8280   Accepted: 2483 Description ...

随机推荐

  1. 表单之input的样式修改

    修改placeholder字体颜色 html5为input添加了原生的占位符属性placeholder,高级浏览器都支持这个属性,例如: <input type="text" ...

  2. CodeForces Contest #1137: Round #545 (Div. 1)

    比赛传送门:CF #1137. 比赛记录:点我. 每次都自闭的 div1 啊,什么时候才能上 IM 呢. [A]Skyscrapers 题意简述: 有一个 \(n\times m\) 的矩阵 \(a_ ...

  3. 为什么Docker比虚拟机快?

    1.Docker有着比虚拟机更少的抽象层,由于Docker不需要Hypervisor实现硬件资源虚拟化,运行在Docker容器上的程序直接使用的都是实际物理机的硬件资源,因此在Cpu.内存利用率上Do ...

  4. Python|绝不乱入的靠谱书单

  5. System.Runtime.InteropServices.COMException (0x800A03EC): 无法访问文件

    使用Microsoft.Office.Interop.Excel 操作 今天在服务器部署,操作程序csv文件转xsl文件的时候,遇到一下问题: System.Runtime.InteropServic ...

  6. saltstack自动化运维系列⑩SaltStack二次开发初探

    saltstack自动化运维系列⑩SaltStack二次开发初探 1.当salt运行在公网或者网络环境较差的条件下,需要配置timeout时间vim /etc/salt/master timeout: ...

  7. cacti系列(一)之cacti的安装及配置监控mysql服务

    简介 Cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数.它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构 ...

  8. 关于windows2008r2系统80端口被system进程占用的问题

    80端口被system占用的问题   今天启动tomcat的时候发现无法启动80端口被占用 通过netstat -ano查看,发现被pid=4的进程占用 检查进程发现是system进程pid=4给占用 ...

  9. LeetCode(32):最长有效括号

    Hard! 题目描述: 给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度. 示例 1: 输入: "(()" 输出: 2 解释: 最长有效括号子串为 ...

  10. java jvm 字节码 实例

    https://blog.csdn.net/wuzhiwei549/article/details/80626677 代码 package strings; //: strings/WhitherSt ...