题意:

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

  

  解法:

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

    整数交点,结果-1即可

  

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5. #include<cmath>
  6. #include<vector>
  7. #include<queue>
  8. #include<set>
  9. #include<map>
  10. using namespace std;
  11. #define eps 1e-6
  12. #define For(i,a,b) for(int i=a;i<=b;i++)
  13. #define Fore(i,a,b) for(int i=a;i>=b;i--)
  14. #define lson l,mid,rt<<1
  15. #define rson mid+1,r,rt<<1|1
  16. #define mkp make_pair
  17. #define pb push_back
  18. #define sz size()
  19. #define met(a,b) memset(a,b,sizeof(a))
  20. #define iossy ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  21. #define fr freopen
  22. #define pi acos(-1.0)
  23. #define Vector Point
  24. typedef pair<int,int> pii;
  25. const long long linf=1LL<<;
  26. const int iinf=<<;
  27. const double dinf=1e17;
  28. const int Mod=1e9+;
  29. typedef long long ll;
  30. typedef long double ld;
  31. const int maxn=;
  32. int n;
  33. struct Point{
  34. ll x,y;
  35. int id;
  36. Point(ll x=,ll y=):x(x),y(y) {}
  37. Point operator - (const Point &a)const { return Point(x-a.x,y-a.y);}
  38. bool operator == (const Point &a)const { return x==a.x && y==a.y; }
  39. };
  40. ll Cross(Vector a,Vector b){
  41. return a.x*b.y-a.y*b.x;
  42. }
  43. ll Dot(Vector a,Vector b) {
  44. return a.x*b.x+a.y*b.y;
  45. }
  46. bool onsg(Point p,Point a1,Point a2){
  47. return Cross(a1-p,a2-p)== && Dot(a1-p,a2-p)<;
  48. }
  49. void ck(ll &c){
  50. if(c>) c=;
  51. else if(c<) c=-;
  52. }
  53. int Ins(Point a1,Point a2,Point b1,Point b2){
  54. if(a1==b1 || a1==b2 || a2==b1 || a2==b2) return ;
  55. if(onsg(a1,b1,b2) || onsg(a2,b1,b2) || onsg(b1,a1,a2) || onsg(b2,a1,a2)) return ;
  56. ll c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1);
  57. ll c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
  58. ck(c1);ck(c2);ck(c3);ck(c4);
  59. return c1*c2< && c3*c4<;
  60. }
  61. set<pair<ll,ll> >c;
  62. void chk(Point p,Vector v,Point q,Vector w){
  63. Vector u=p-q;
  64. ll v1=Cross(w,u),v2=Cross(v,w);
  65. if(abs(v1*v.x)%v2!= || abs(v1*v.y)%v2!=) return ;
  66. ll xx,yy;
  67. xx=p.x+v.x*v1/v2;yy=p.y+v.y*v1/v2;
  68. c.insert(mkp(xx,yy));
  69. }
  70. struct segm{
  71. Point p1,p2;
  72. };
  73. segm ss[maxn];
  74. Point p1,p2;
  75. void solve(){
  76. iossy;
  77. cin>>n;
  78. int ans=;
  79. For(i,,n){
  80. cin>>p1.x>>p1.y>>p2.x>>p2.y;
  81. ss[i].p1=p1;ss[i].p2=p2;
  82. ans+=__gcd(abs(ss[i].p2.x-ss[i].p1.x),abs(ss[i].p2.y-ss[i].p1.y))+;
  83. }
  84. For(i,,n){
  85. c.clear();
  86. For(j,i+,n){
  87. int ct=Ins(ss[i].p1,ss[i].p2,ss[j].p1,ss[j].p2);
  88. if(ct) chk(ss[i].p1,ss[i].p2-ss[i].p1,ss[j].p1,ss[j].p2-ss[j].p1);
  89. }
  90. ans-=c.sz;
  91. }
  92. //cout<<ans-c.sz<<endl;
  93. cout<<ans<<endl;
  94. }
  95. int main(){
  96. int t=;
  97. // For(i,1,t) printf("Case #%d: ",i);
  98. solve();
  99. return ;
  100. }

[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. 使用Jupyter lab前应该读的几篇文章

    知乎上的一篇文章: 如何优雅的使用Jupyter? Jupyter Lab原来还有如下使用方式: 执行Shell命令 Hintland(提示命令).snippets(插入代码段).一键美化代码等功能( ...

  2. D - Laying Cables Gym - 100971D (单调栈)

    题目链接:https://cn.vjudge.net/problem/Gym-100971D 题目大意:给你n个城市的信息,每一个城市的信息包括坐标和人数,然后让你找每一个城市的父亲,作为一个城市的父 ...

  3. mysql 原理 ~ change buffer

    一 简介:今天咱们来聊聊mysql的change buffer二 详细说明   1 +-change Buffer和数据页一样,也是物理页的一个组成部分,数据结构也是一颗B+树,这棵B+树放在共享表空 ...

  4. JNI打通java和c

    1.JNI简介 The Java Native Interface (JNI) is a programming framework that enables Java code running in ...

  5. WPF开发中的多线程的问题

    今天帮助同事做了一个WPF版的多线程demo,分享给大家. 要实现的问题就是非主线程thread1 去后台不停的取新数据,当有新数据的时候就会展示到前台. 我给他做的demo实现一个按秒的计数器,随着 ...

  6. 【逆向知识】VS程序反汇编找main函数

    工具:OllyICE 调试快捷键说明: F2键:设置断点,只要在光标定位的位置 F4键:程序运行到光标处 F7键:单步步入.功能同单步步过(F8)类似,区别是遇到 CALL 等子程序时会进入其中,进入 ...

  7. Python3 configparse模块(配置)

    ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 注意:在 ...

  8. python内置模块之unittest测试(五)

    系列文章 python模块分析之random(一) python模块分析之hashlib加密(二) python模块分析之typing(三) python模块分析之logging日志(四) pytho ...

  9. 四、Logisitic Regssion练习(转载)

    转载:http://www.cnblogs.com/tornadomeet/archive/2013/03/16/2963919.html 牛顿法:http://blog.csdn.net/xp215 ...

  10. Bootstrap3.0学习第五轮(表格)

    详情请查看 http://aehyok.com/Blog/Detail/11.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:h ...