注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn。

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <stack>
using namespace std;
typedef long long ll;
#define T int t_;Read(t_);while(t_--)
#define dight(chr) (chr>='0'&&chr<='9')
#define alpha(chr) (chr>='a'&&chr<='z')
#define INF (0x3f3f3f3f)
#define maxn (300005)
#define maxm (10005)
#define mod 1000000007
#define ull unsigned long long
#define repne(x,y,i) for(i=(x);i<(y);++i)
#define repe(x,y,i) for(i=(x);i<=(y);++i)
#define repde(x,y,i) for(i=(x);i>=(y);--i)
#define repdne(x,y,i) for(i=(x);i>(y);--i)
#define ri register int
inline void Read(int &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
inline void Read(ll &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if
(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
ll g[],sx[],sy[],ex[],ey[];
set<pair<ll,ll> >se[];
ll gcd(ll x,ll y){
return (y==)?x:gcd(y,x%y);
}
int main()
{
freopen("a.in","r",stdin);
freopen("b.out","w",stdout);
//对于每一条线段的每一个整数点可由二元组(sx+k*(ex-sx)/gcd(ex-sx,sy-ey),sy+k*(ey-sy)/gcd(ex-sx,sy-ey))得到
//由此可得到线段中所有的点个数为sum((ex-sx)/gcd(ex-sx,sy-ey)+1)
//由于存在重复点需要减去重复点的重复个数
//枚举解方程,若有解则可以确定此点的位置,由于n条线段最多产生n*(n-1)/2个交点
int n;
ri i,j,k;
Read(n);
repe(,n,i) Read(sx[i]),Read(sy[i]),Read(ex[i]),Read(ey[i]),g[i] = gcd(abs(ex[i]-sx[i]),abs(sy[i]-ey[i]));
ll ans = ;
repe(,n,i) ans = ans + g[i] + ;
//sx[i] + s*(ex[i]-sx[i])/g[i] = sx[j] + t*(ex[j]-sx[j])/g[j]
//sy[i] + s*(ey[i]-sy[i])/g[i] = sy[j] + t*(ey[j]-sy[j])/g[j]
repe(,n,i){
ll a = (ex[i] - sx[i])/g[i],b = (ey[i] - sy[i])/g[i];
ll lm = a / gcd(abs(a),abs(b)) * b;
repe(i+,n,j){
ll c = (ex[j]-sx[j])/g[j],d = (ey[j]-sy[j])/g[j];
if(a == ){
if(c != ){
if((sx[i] - sx[j]) % c == ){
ll t = (sx[i] - sx[j]) / c,x = sx[j] + t * c,y = sy[j] + t * d;
if((x - sx[i])*(ex[i]-sx[i]) >= && abs(x-sx[i])<=abs(ex[i]-sx[i]) && (x - sx[j])*(ex[j]-sx[j]) >= && abs(x-sx[j])<=abs(ex[j]-sx[j]) && (y - sy[i])*(ey[i]-sy[i]) >= && abs(y-sy[i])<=abs(ey[i]-sy[i]) && (y - sy[j])*(ey[j]-sy[j]) >= && abs(y-sy[j])<=abs(ey[j]-sy[j])){ se[i].insert(make_pair(x,y));
// --ans;
}
}
}
continue;
}
if(b == ){
if(d != ){
if((sy[i] - sy[j]) % d == ){
ll t = (sy[i] - sy[j]) / d,x = sx[j] + t * c,y = sy[j] + t * d;
if((x - sx[i])*(ex[i]-sx[i]) >= && abs(x-sx[i])<=abs(ex[i]-sx[i]) && (x - sx[j])*(ex[j]-sx[j]) >= && abs(x-sx[j])<=abs(ex[j]-sx[j]) && (y - sy[i])*(ey[i]-sy[i]) >= && abs(y-sy[i])<=abs(ey[i]-sy[i]) && (y - sy[j])*(ey[j]-sy[j]) >= && abs(y-sy[j])<=abs(ey[j]-sy[j])){ se[i].insert(make_pair(x,y));
// --ans;
}
}
}
continue;
}
if(c * lm / a == d * lm / b) continue;
ll tc = c,td = d;
c *= lm / a,d *= lm/b;
if(c - d == ) continue;
if(((sx[i]-sx[j])*lm/a - (sy[i]-sy[j])*lm/b) % (c-d) != ) continue;
else{ ll t = ((sx[i]-sx[j])*lm/a - (sy[i]-sy[j])*lm/b) / (c-d),c = tc,d = td,x = sx[j] + t * c,y = sy[j] + t * d;
if((x - sx[i])*(ex[i]-sx[i]) >= && abs(x-sx[i])<=abs(ex[i]-sx[i]) && (x - sx[j])*(ex[j]-sx[j]) >= && abs(x-sx[j])<=abs(ex[j]-sx[j]) && (y - sy[i])*(ey[i]-sy[i]) >= && abs(y-sy[i])<=abs(ey[i]-sy[i]) && (y - sy[j])*(ey[j]-sy[j]) >= && abs(y-sy[j])<=abs(ey[j]-sy[j])){ se[i].insert(make_pair(x,y));
//--ans;
}
}
}
}
for(int i = ;i <= n;++i) ans -= (int)se[i].size();
cout << ans << endl;
return ;
}

Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points的更多相关文章

  1. Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...

  2. Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)

    题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...

  3. Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers

    C. Classy Numbers 题目链接:https://codeforces.com/contest/1036/problem/C 题意: 给出n个询问,每个询问给出Li,Ri,问在这个闭区间中 ...

  4. Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码

    A题链接:https://codeforces.com/contest/1036/problem/A A题AC代码: #include <stdio.h> #include <std ...

  5. Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers

    实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

随机推荐

  1. Android(java)学习笔记162:开发一个多界面的应用程序之两种意图

    1.两种意图: (1)显式意图: 在代码里面用intent设置要开启Activity的字节码.class文件: (2)隐式意图: Android(java)学习笔记218:开发一个多界面的应用程序之人 ...

  2. 利用条件运算符的嵌套来完成此题: 学习成绩>= 90分的同学用A表示, 60-89分之间的用B表示, 60分以下的用C表示。

    题目:利用条件运算符的嵌套来完成此题: 学习成绩>= 90分的同学用A表示, 60-89分之间的用B表示, 60分以下的用C表示. 程序分析:(a> b)?a:b这是条件运算符的基本例子. ...

  3. Ubuntu 18的网络配置

    包括Ubuntu 18.04和18.10,设置为静态IP及DNS. sudo vim /etc/netplan/50-cloud-init.yaml network: ethernets: enp4s ...

  4. FastDFS和集中存储方式对比

    指标 FastDFS   NFS  集中存储设备如NetApp.NAS 线性扩容性  高  差  差 文件高并发访问性能 高 差  一般 文件访问方式 专有API POSIX  支持POSIX 硬件成 ...

  5. zabbix监控流程图

  6. [模板] Miller-Rabin 素数测试

    细节挺多的.. #include<iostream> #include<cstdlib> #include<cstdio> #include<ctime> ...

  7. laravel 数据导出

    支持:php 7.0 以上 三种方案总结介绍: 第一种:最简单且不会有长久隐患.但不适合数据量多    第二种:  适合中等数据量,不会有长久隐患.但导出时极占内存   第三种:适合大量数据,不会占据 ...

  8. spring-mvc jackson配置json为空不输出

    使用的spring-mvc版本是4.1.6,jackson版本是2.1.4 在spring-mvc配置文件中添加以下代码就行 <mvc:annotation-driven> <mvc ...

  9. 条款5:了解C++默默编写并调用哪些函数(Know what functions C++ silently writes and calls)

    1.default costructor  / copy constructor / copy assignment 者三者的区别? 特别是copy constructor & copy as ...

  10. htmlpurifier的使用

    什么是htmlpurifier?? HTML Purifier是一个可以用来移除所有恶意代码(XSS),而且还能确保你的页面遵循W3C的标准规范的PHP类库. 在php里解决XSS最简单的方法是使用h ...