EDU 50 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 利用克莱姆法则计算线段交点的更多相关文章
- CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)
https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖 ...
- hdu 1086(计算几何入门题——计算线段交点个数)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2 ...
- 利用sklearn计算文本相似性
利用sklearn计算文本相似性,并将文本之间的相似度矩阵保存到文件当中.这里提取文本TF-IDF特征值进行文本的相似性计算. #!/usr/bin/python # -*- coding: utf- ...
- 利用Python计算π的值,并显示进度条
利用Python计算π的值,并显示进度条 第一步:下载tqdm 第二步;编写代码 from math import * from tqdm import tqdm from time import ...
- Educational Codeforces Round 46 C - Covered Points Count
C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...
- Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】
<题目链接> <转载于 >>> > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...
- Ajax实例一:利用服务器计算
Ajax实例一:利用服务器计算 HTML代码 //输入两个数 <input id="number1" type="number"> <inpu ...
- Covered Points Count(思维题)
C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- 利用函数计算构建微信小程序的Server端
10分钟上线 - 利用函数计算构建微信小程序的Server端-博客-云栖社区-阿里云 https://yq.aliyun.com/articles/435430 函数计算 读写 oss import ...
随机推荐
- Java匹马行天下之JavaWeb核心技术——JSP(续一)
十二.JSP表单处理 我们在浏览网页的时候,经常需要向服务器提交信息,并让后台程序处理.浏览器中使用 GET 和 POST 方法向服务器提交数据. GET 方法 GET方法将请求的编码信息添加在网 ...
- iOS 注释
1) 参数的注释: UIButton *btnSend;/**< 发送按钮 */ 效果: 2) 方法的注释: type1(无参数): /** table 相关设置 */ -(void)confi ...
- PHP xdebug API接口优化揪出了getimagesize这个鬼
在API优化list中,公司客户系统的服务号客服有个获取聊天消息的接口getHistory请求时间很长,就去优化了下,记下过程. 一,配置环境,追踪使用Xdebug: 1.在https://xdebu ...
- Something wrong with EnCase v8 index search results
My friend told me that she installed EnCase v8.05 on her workstation which OS version is Win 10. She ...
- EasyUI combobox下拉列表实现搜索过滤(模糊匹配)
项目中的某个下拉列表长达200多个项,这么巨大的数量一个一个找眼镜都得看花,于是就得整了个搜索功能.看网上别人帖子有只能前缀匹配的方案,但只能前缀匹配的话用起来也不是很方便.于是就记录一下模糊匹配的方 ...
- 探秘最小生成树&&洛谷P2126题解
我在这里就讲两种方法 Prim 和 Kruscal Kruscal kruscal的本质其实是 排序+并查集 ,是生成树中避圈法的推广 算法原理如下 (1)将连通带权图G=<n,m>的各条 ...
- 【错误】【vscode】"'#' not expected here"
今天使用vscode发现完整的代码报错了,但依然可以运行
- iOS的录屏功能
iOS的录屏功能其实没什么好说的,因为网上的教程很多,但是网上的Demo无一例外几乎都有一个bug,那就是iPad上会出现闪退,这也体现了国内的教程文档的一个特点,就是抄袭,教程几乎千篇一律,bug也 ...
- 使用python画3D线条
"""用于验证整体趋势正确性""" #!python3 #-*- coding:utf-8 -*- import matplotlib as ...
- 【linux】【qt5界面】【系统托盘图标的实现】
前言: 博主最近在做一个聊天软件,虽然技术不咋滴,但遇到点干货肯定是要跟大家分享的啦.下面就给大家分享一个qt实现程序隐藏才系统托盘的技巧. 装备: 系统:linux, qt版本:5.9.2,GCC: ...