Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points
注释上都有解析了,就不写了吧,去重的问题就用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的更多相关文章
- Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count
Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...
- 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)的个数,那么实 ...
- Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers
C. Classy Numbers 题目链接:https://codeforces.com/contest/1036/problem/C 题意: 给出n个询问,每个询问给出Li,Ri,问在这个闭区间中 ...
- 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 ...
- Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers
实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 ...
- 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 ...
随机推荐
- Qt获取本机IP地址
Qt获取本机IP地址: Qt版本:4.8.6 #include <QtNetwork/QNetworkInterface.h> QString ipAddr; QList<QHost ...
- 【人工智能系列】python的Quepy库的学习
第一篇 了解 什么是Quepy quepy是一个Python框架改造自然语言问题在数据库查询语言查询.它可以很容易地定制不同类型的问题,在自然语言和数据库查询.因此,用很少的代码,你可以建立自己的系统 ...
- Eclipse--java.lang.OutOfMemoryError: PermGen space
这一段时间,Eclipse总是死掉,几乎是稍微操作快一点就会死掉,几分钟一次,搞得人郁闷至极.浪费了不少时间,在网上搜了下,看到很多朋友也出现类似的情况,在网上求救,但是网上的办法都只是说通过修改ec ...
- (转)Spring的概述
http://blog.csdn.net/yerenyuan_pku/article/details/69663685 Spring的概述 什么是Spring 据度娘所载: Spring是一个开源框架 ...
- python_对字符串操作.join() 效率 比 + 效率高
将列表中的字符拼接成字符串时,有两种方式 方式1:使用join()方法,将列表转为字符串 方式2:使用+运算符,循环遍历 import time str1 = ['a','b','c','d','e' ...
- 创建线程的三种方式_Callable和Runnable的区别
Java 提供了三种创建线程的方法 通过实现Runnable接口 通过继承Thread接口 通过Callable和Future创建线程 通过实现 Runnable 接口来创建线程 public cla ...
- ubuntu命令行转换图片像素大小
convert -resize 512x256 00433.png 00001.png 1.512和256之间是x(就是字母那个x),用' * '反而会报错 2.这个命令会按照原图的比例进行转换 3. ...
- 二叉排序树BST
注意:对一个二叉排序树进行中序遍历时,得到的序列是一个按值从小到大排列的有序序列 查找性能的分析:
- 最短路 || UOJ 19 寻找道路
UOJ j19 寻找道路 在有向图G中,每条边的长度均为 1,现给定起点和终点,请你在图中找一条从起点到终点的最短路径,该路径满足以下条件: 路径上的所有点的出边所指向的点都直接或间接与终点连通. * ...
- POJ-3624-背包问题
它这个问题问的是,在有限的容量下,能装下的最大价值是多少. 所以我们可以递归求解,记忆性递归,用二维数组,但是这样的话就会超内存,所以我们只能用动规来写,而且不能开二维数组, 只能用滚动数组. 我们设 ...