[CodeForces-1036E] Covered Points 暴力 GCD 求交点
题意:
在二维平面上给出n条不共线的线段,问这些线段总共覆盖到了多少个整数点
解法:
用GCD可求得一条线段覆盖了多少整数点,然后暴力枚举线段,求交点,对于相应的
整数交点,结果-1即可
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<iostream>
- #include<cmath>
- #include<vector>
- #include<queue>
- #include<set>
- #include<map>
- using namespace std;
- #define eps 1e-6
- #define For(i,a,b) for(int i=a;i<=b;i++)
- #define Fore(i,a,b) for(int i=a;i>=b;i--)
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define mkp make_pair
- #define pb push_back
- #define sz size()
- #define met(a,b) memset(a,b,sizeof(a))
- #define iossy ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- #define fr freopen
- #define pi acos(-1.0)
- #define Vector Point
- typedef pair<int,int> pii;
- const long long linf=1LL<<;
- const int iinf=<<;
- const double dinf=1e17;
- const int Mod=1e9+;
- typedef long long ll;
- typedef long double ld;
- const int maxn=;
- int n;
- struct Point{
- ll x,y;
- int id;
- Point(ll x=,ll y=):x(x),y(y) {}
- Point operator - (const Point &a)const { return Point(x-a.x,y-a.y);}
- bool operator == (const Point &a)const { return x==a.x && y==a.y; }
- };
- ll Cross(Vector a,Vector b){
- return a.x*b.y-a.y*b.x;
- }
- ll Dot(Vector a,Vector b) {
- return a.x*b.x+a.y*b.y;
- }
- bool onsg(Point p,Point a1,Point a2){
- return Cross(a1-p,a2-p)== && Dot(a1-p,a2-p)<;
- }
- void ck(ll &c){
- if(c>) c=;
- else if(c<) c=-;
- }
- int Ins(Point a1,Point a2,Point b1,Point b2){
- if(a1==b1 || a1==b2 || a2==b1 || a2==b2) return ;
- if(onsg(a1,b1,b2) || onsg(a2,b1,b2) || onsg(b1,a1,a2) || onsg(b2,a1,a2)) return ;
- ll c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1);
- ll c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
- ck(c1);ck(c2);ck(c3);ck(c4);
- return c1*c2< && c3*c4<;
- }
- set<pair<ll,ll> >c;
- void chk(Point p,Vector v,Point q,Vector w){
- Vector u=p-q;
- ll v1=Cross(w,u),v2=Cross(v,w);
- if(abs(v1*v.x)%v2!= || abs(v1*v.y)%v2!=) return ;
- ll xx,yy;
- xx=p.x+v.x*v1/v2;yy=p.y+v.y*v1/v2;
- c.insert(mkp(xx,yy));
- }
- struct segm{
- Point p1,p2;
- };
- segm ss[maxn];
- Point p1,p2;
- void solve(){
- iossy;
- cin>>n;
- int ans=;
- For(i,,n){
- cin>>p1.x>>p1.y>>p2.x>>p2.y;
- ss[i].p1=p1;ss[i].p2=p2;
- ans+=__gcd(abs(ss[i].p2.x-ss[i].p1.x),abs(ss[i].p2.y-ss[i].p1.y))+;
- }
- For(i,,n){
- c.clear();
- For(j,i+,n){
- int ct=Ins(ss[i].p1,ss[i].p2,ss[j].p1,ss[j].p2);
- if(ct) chk(ss[i].p1,ss[i].p2-ss[i].p1,ss[j].p1,ss[j].p2-ss[j].p1);
- }
- ans-=c.sz;
- }
- //cout<<ans-c.sz<<endl;
- cout<<ans<<endl;
- }
- int main(){
- int t=;
- // For(i,1,t) printf("Case #%d: ",i);
- solve();
- return ;
- }
[CodeForces-1036E] Covered Points 暴力 GCD 求交点的更多相关文章
- Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】
<题目链接> <转载于 >>> > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...
- Codeforces 1036E. Covered Points
又一次写起了几何.... 特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个set里,对每一个set,每次删除set.size()即可 重点在于判断两条线 ...
- CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)
https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖 ...
- codeforces 1000C - Covered Points Count 【差分】
题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...
- C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)
C - Covered Points Count CodeForces - 1000C You are given nn segments on a coordinate line; each end ...
- EDU 50 E. Covered Points 利用克莱姆法则计算线段交点
E. Covered Points 利用克莱姆法则计算线段交点.n^2枚举,最后把个数开方,从ans中减去. ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算. #include ...
- Educational Codeforces Round 46 C - Covered Points Count
C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...
- 个人项目作业$\cdot$求交点个数
个人项目作业\(\cdot\)求交点个数 一.作业要求简介 本次作业是北航计算机学院软件工程课程的个人项目作业,个人开发能力对于软件开发团队是至关重要的,本项目旨在通过一个求几何图形的交点的需求来使学 ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
随机推荐
- 使用Jupyter lab前应该读的几篇文章
知乎上的一篇文章: 如何优雅的使用Jupyter? Jupyter Lab原来还有如下使用方式: 执行Shell命令 Hintland(提示命令).snippets(插入代码段).一键美化代码等功能( ...
- D - Laying Cables Gym - 100971D (单调栈)
题目链接:https://cn.vjudge.net/problem/Gym-100971D 题目大意:给你n个城市的信息,每一个城市的信息包括坐标和人数,然后让你找每一个城市的父亲,作为一个城市的父 ...
- mysql 原理 ~ change buffer
一 简介:今天咱们来聊聊mysql的change buffer二 详细说明 1 +-change Buffer和数据页一样,也是物理页的一个组成部分,数据结构也是一颗B+树,这棵B+树放在共享表空 ...
- JNI打通java和c
1.JNI简介 The Java Native Interface (JNI) is a programming framework that enables Java code running in ...
- WPF开发中的多线程的问题
今天帮助同事做了一个WPF版的多线程demo,分享给大家. 要实现的问题就是非主线程thread1 去后台不停的取新数据,当有新数据的时候就会展示到前台. 我给他做的demo实现一个按秒的计数器,随着 ...
- 【逆向知识】VS程序反汇编找main函数
工具:OllyICE 调试快捷键说明: F2键:设置断点,只要在光标定位的位置 F4键:程序运行到光标处 F7键:单步步入.功能同单步步过(F8)类似,区别是遇到 CALL 等子程序时会进入其中,进入 ...
- Python3 configparse模块(配置)
ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 注意:在 ...
- python内置模块之unittest测试(五)
系列文章 python模块分析之random(一) python模块分析之hashlib加密(二) python模块分析之typing(三) python模块分析之logging日志(四) pytho ...
- 四、Logisitic Regssion练习(转载)
转载:http://www.cnblogs.com/tornadomeet/archive/2013/03/16/2963919.html 牛顿法:http://blog.csdn.net/xp215 ...
- Bootstrap3.0学习第五轮(表格)
详情请查看 http://aehyok.com/Blog/Detail/11.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:h ...