注释上都有解析了,就不写了吧,去重的问题就用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. CMSIS的简介

    Cortex微控制器软件接口标准(Cortex Microcontroller Software Interface Standard)是ARM和一些编译器厂家以及半导体厂家共同遵循的一套标准,是由A ...

  2. redis集群架构(含面试题解析)

    老规矩,我还是以循序渐进的方式来讲,我一共经历过三套集群架构的演进! Replication+Sentinel 这套架构使用的是社区版本推出的原生高可用解决方案,其架构图如下! 这里Sentinel的 ...

  3. Android Studio 中文件查询方法总结

    搜索单词 Windows: Ctrl + F Mac   : Cmd + F 会在当前激活的文件上查询输入的关键字,以高亮显示 跳转行 Windows: Ctrl + L Mac   : Cmd + ...

  4. js中重载问题

    在js中是没有重载的  但是  Arguments对象(可以实现模拟重载的效果) 利用arguments对象的length属性,可以获取函数接收的参数的个数 例如: function add(){ i ...

  5. python基础一 day2 数据类型

    int:        bool: 类型转换: str到int有条件,str必须是数字, "123e"是错误的 bool转换为int类型,需要int(x)  结果:  结果: 空字 ...

  6. c++ extern

    一.extern关键字的作用 文件中定义的全局变量的可见性扩展到整个程序是在链接完成之后,而在编译阶段,他们的可见性仍局限于各自的文件. 编译器的目光不够长远,编译器没有能够意识到,某个变量符号虽然不 ...

  7. There is no Action mapped for namespace [/] and action name [updateUser] associated with context path [].

    在使用Struts2的时候,遇到了这个问题. 原因分析: 找不到指定的路径, 那么就是struts.xml的内容问题, 或者是struts.xml的文件位置存在问题. struts2默认是应该放在sr ...

  8. centos nginx uwsgi django

    doc link uwsgi link video link

  9. css 给div 添加滚动条样式hover 效果

             css .nui-scroll { margin-left: 100px; border: 1px solid #000; width: 200px; height: 100px; ...

  10. More Effective C++ - 章节二 : 操作符(operators)

    5. 对定制的 "类型转换函数" 保持警觉 允许编译器执行隐式类型转换,害处多过好处,不要提供转换函数,除非你确定需要. class foo { foo(int a = 0, in ...