E. Covered Points

利用克莱姆法则计算线段交点。n^2枚举,最后把个数开方,从ans中减去。

ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'
//#define R register
#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /*-----------------------showtime----------------------*/ const int maxn = ;
struct node{
ll x1,y1,x2,y2;
}a[maxn];
ll ans = ;
map<pii, int> mp; void cal(int i,int j){ ll x1 = a[i].x1,y1 = a[i].y1,x2 = a[i].x2,y2 = a[i].y2; ll x3 = a[j].x1,y3 = a[j].y1,x4 = a[j].x2,y4 = a[j].y2; ll a = (y1-y2) * (x4-x3) - (x2-x1)*(y3-y4);
ll t = (x2*y1 - x1*y2)*(x4-x3) - (x2-x1)*(x4*y3 - x3*y4);
ll p = (y1-y2) * (x4*y3-x3*y4) - (x2*y1-x1*y2)*(y3-y4); if(a == )return;
if(t % a || p % a) return;
t = t/a; p = p/a; if(x1 > x2) swap (x1,x2); if(t < x1 || t > x2) return; if(x3 > x4) swap (x3,x4); if(t < x3 || t > x4) return; if(y1 > y2) swap(y1,y2); if(p < y1 || p > y2) return; if(y3 > y4) swap(y3,y4); if(p < y3 || p > y4) return; mp[pii(t,p)] ++;
}
int main(){
int n; scanf("%d", &n);
for(int i=; i<=n; i++){
ll x1,y1,x2,y2;
scanf("%lld%lld%lld%lld", &x1, &y1, &x2, & y2);
a[i] = (node){x1,y1,x2,y2};
ll d1 = abs(x1 - x2);
ll d2 = abs(y1 - y2);
ans += __gcd(d1, d2) + ;
} for(int i=; i<=n; i++){
for(int j=; j<=n; j++){
if(i == j) continue;
cal(i,j);
}
} for(auto p : mp){
ans -= (int)sqrt(p.se);
}
printf("%lld\n", ans); return ;
}

EDU 50 E. Covered Points 利用克莱姆法则计算线段交点的更多相关文章

  1. CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)

    https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖 ...

  2. hdu 1086(计算几何入门题——计算线段交点个数)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2 ...

  3. 利用sklearn计算文本相似性

    利用sklearn计算文本相似性,并将文本之间的相似度矩阵保存到文件当中.这里提取文本TF-IDF特征值进行文本的相似性计算. #!/usr/bin/python # -*- coding: utf- ...

  4. 利用Python计算π的值,并显示进度条

    利用Python计算π的值,并显示进度条  第一步:下载tqdm 第二步;编写代码 from math import * from tqdm import tqdm from time import ...

  5. Educational Codeforces Round 46 C - Covered Points Count

    C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...

  6. Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】

    <题目链接> <转载于 >>>  > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...

  7. Ajax实例一:利用服务器计算

    Ajax实例一:利用服务器计算 HTML代码 //输入两个数 <input id="number1" type="number"> <inpu ...

  8. Covered Points Count(思维题)

    C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

  9. 利用函数计算构建微信小程序的Server端

    10分钟上线 - 利用函数计算构建微信小程序的Server端-博客-云栖社区-阿里云 https://yq.aliyun.com/articles/435430 函数计算  读写 oss import ...

随机推荐

  1. iOS开发 8小时时差问题

    今天调试遇到时间计算的问题,发现怎么算都会有差别,后来仔细观察,发现有8小时的时差…… 这篇文章解释的很好,用到了,因此记之. ios有关时间打印出来差8小时的问题

  2. ld: warning: directory not found for option ''

    iOS开发中经常遇到这样的警告,如图所示: 原因是存在未用到的目录. 解决方法:选择Build Settings,找到Search Paths中的Library Search Paths,如下图 删除 ...

  3. Pow共识算法

    谈到哈希算法,每个程序员都不陌生,但是谈到比特币共识算法PoW,如果没有接触过的技术人员可能觉得应该会很复杂,毕竟全球的比特币节点数量如此庞大,达成共识的算法应该不会很简单.但其实如果你已掌握哈希算法 ...

  4. JavaScript数据结构——集合的实现与应用

    与数学中的集合概念类似,集合由一组无序的元素组成,且集合中的每个元素都是唯一存在的.可以回顾一下中学数学中集合的概念,我们这里所要定义的集合也具有空集(即集合的内容为空).交集.并集.差集.子集的特性 ...

  5. 浅谈 ASCII、Unicode、UTF-8,一目了然

    对于ASCII.Unicode.UTF-8这三种编码方式我们经常用到,也经常挂到嘴边,但他们是怎么来的,为什么要存在,具体是怎么个规则,我们并没有做深入了解,下面,就带你看一下他们到底是怎么回事吧…… ...

  6. 进军pc市场 华为剑走偏锋可有戏?

    尽管官方并未正式公布,但在前段时间,华为将要进军PC市场的消息在业内传得沸沸扬扬,据知情人士曝料,其第一款个人电脑将在今年4月上线.而华为将进军PC市场的消息,对其他智能手机厂商来说又意味着什么呢? ...

  7. 自己动手写Spring框架--IOC、MVC

    对于一名Java开发人员,我相信没有人不知道 Spring 框架,而且也能够轻松就说出 Spring 的特性-- IOC.MVC.AOP.ORM(batis). 下面我想简单介绍一下我写的轻量级的 S ...

  8. Java中...的作用

    Java中...的作用,代表接收若干个相同类型的参数 public void testFunction(int...arr){    //接收若干个int类型的参数     for (int i:ar ...

  9. Go中的日志及第三方日志包logrus

    有别的语言使用基础的同学工作中都会接触到日志的使用,Go中自然也有log相关的实现.Go log模块主要提供了3类接口,分别是 "Print .Panic .Fatal ",对每一 ...

  10. Go基础语法学习

    Go语言基础 Go是一门类似C的编译型语言,但是它的编译速度非常快.这门语言的关键字总共也就二十五个,比英文字母还少一个,这对于我们的学习来说就简单了很多.先让我们看一眼这些关键字都长什么样: 下面列 ...