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 ...
随机推荐
- 用JS获取Html中所有图片文件流然后替换原有链接
function displayHtmlWithImageStream(bodyHtml) { var imgReg = /<img.*?(?:>|\/>)/gi; var arr ...
- loadrunner:文本检查点web_reg_find和web_find两个函数的区别
web_reg_find是先注册(register)后查找的:使用时将它放在请求语句的前面. 而web_find是查找前面的请求结果:使用时将它放在请求语句的后面. 另二者的参数也完成不一样的,web ...
- FPGA编程技巧系列之按键边沿检测
抖动的产生: 通常的按键所用开关为机械弹性开关,当机械触点断开.闭合时,由于机械触点的弹性作用,一个按键开关在闭合时不会马上稳定地接通,在断开时也不会一下子断开.因而在闭合及断开的瞬间均伴随有一连串的 ...
- COGS 2274. [HEOI 2016] tree
★☆ 输入文件:heoi2016_tree.in 输出文件:heoi2016_tree.out 简单对比时间限制:1 s 内存限制:128 MB 这道题数据弱到炸了 . 第一次做用树刨 ...
- 洛谷 P1507 NASA的食物计划
题目背景 NASA(美国航空航天局)因为航天飞机的隔热瓦等其他安 全技术问题一直大伤脑筋,因此在各方压力下终止了航天 飞机的历史,但是此类事情会不会在以后发生,谁也无法 保证,在遇到这类航天问题时,解 ...
- 洛谷 P1361 小猫爬山
题目描述 WD和LHX饲养了N只小猫,这天,小猫们要去爬山.经历了千辛万苦,小猫们终于爬上了山顶,但是疲倦的它们再也不想徒步走下山了. WD和LHX只好花钱让它们坐索道下山.索道上的缆车最大承重量为W ...
- Netbeans Makefile: recipe for target 'XXX' failed 运行failed(退出值 -1073741511 找不到C/C++库文件,关键字
今天不知怎么的又出错了 吐血了 找不到NULL new等关键字了 看到知乎上有人和我一个问题,怎么办?很简单卸载了以前的cygwin和netbeans然后重装,我重装时没有把以前的cygwin ...
- Android(java)学习笔记180:多媒体之图形的变化处理
1. 图形的缩放 (1)布局文件activity_main.xml如下: <LinearLayout xmlns:android="http://schemas.android.com ...
- 判断请求是否为ajax
判断请求是否为ajax 转载:http://www.cnblogs.com/tony-jingzhou/archive/2012/07/30/2615612.html x-requested-with ...
- Unity整合Asp.Net MVC
先来看一下我们的解决方案 我们建立Yubay.Models项目, using System; using System.Collections.Generic; using System.Data.E ...