又一次写起了几何。。。。

特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个set里,对每一个set,每次删除set.size()即可

重点在于判断两条线段的交点是否是一个整数点,需要特殊考虑,平行和y=kx+b关系式不能成立的情况

我的代码中没有判断除数为0的情况(因为不会报错,我也就没写23333,但不影响结果

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<climits>
#include<bitset>
#include<random>
#include <ctime>
#include <cassert>
#include <complex>
#include <cstring>
#include <chrono>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);
#define left asfdasdasdfasdfsdfasfsdfasfdas1
#define tan asfdasdasdfasdfasfdfasfsdfasfdas
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned int un;
const int desll[][]={{,},{,-},{,},{-,}};
const int mod=1e9+;
const int maxn=5e5+;
const int maxm=1e5+;
const double eps=1e-;
int n,k,m;
int ar[maxn][];
int xl[],yl[];
set<pair<int,int>>se;
bool is_interge(double x){
return fabs(x-round(x))<=eps;
} bool equal(double a,double b){
return fabs(a-b)<=eps;
}
void getKB(int x,double& k,double& b)
{
k=(double)(ar[x][]-ar[x][])/(ar[x][]-ar[x][]);
b=(double)ar[x][]-k*ar[x][];
}
void func(int i,int j)
{
if(ar[i][]==ar[i][]&&ar[j][]==ar[j][])return ;
if(ar[i][]==ar[i][]&&ar[j][]==ar[j][])return ;
if(equal((double)(ar[i][]-ar[i][])/(ar[i][]-ar[i][]),
(double)(ar[j][]-ar[j][])/(ar[j][]-ar[j][])))return ; double k1,k2,b1,b2;
getKB(i,k1,b1);
getKB(j,k2,b2);
double x,y;
if(ar[i][]==ar[i][]){
x=ar[i][];
y=k2*x+b2;
}
else if(ar[j][]==ar[j][]){
x=ar[j][];
y=k1*x+b1;
}
else{
x=(b2-b1)/(k1-k2);
y=k1*x+b1;
}
if(!is_interge(x) || !is_interge(y))return ;
int xx=round(x),yy=round(y);
if(xx>=min(ar[i][],ar[i][])&&xx<=max(ar[i][],ar[i][])&&
yy>=min(ar[i][],ar[i][])&&yy<=max(ar[i][],ar[i][])&&
xx>=min(ar[j][],ar[j][])&&xx<=max(ar[j][],ar[j][])&&
yy>=min(ar[j][],ar[j][])&&yy<=max(ar[j][],ar[j][]))
se.insert(make_pair(xx,yy));
} int main()
{
scanf("%d",&n);
for(int i=;i<n;i++){
for(int j=;j<;j++)scanf("%d",&ar[i][j]);
}
ll ans=;
for(int i=;i<n;i++){
int xx=abs(ar[i][]-ar[i][]);
int yy=abs(ar[i][]-ar[i][]);
ans += __gcd(xx,yy)+;
}
for(int i=;i<n;i++){
se.clear();
for(int j=i+;j<n;j++){
func(i,j);
}
ans-=se.size();
}
printf("%I64d\n",ans); return ;
}

Codeforces 1036E. Covered Points的更多相关文章

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

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

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

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

  3. codeforces 1000C - Covered Points Count 【差分】

    题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...

  4. C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)

    C - Covered Points Count CodeForces - 1000C You are given nn segments on a coordinate line; each end ...

  5. Educational Codeforces Round 46 C - Covered Points Count

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

  6. Covered Points Count(思维题)

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

  7. EDU 50 E. Covered Points 利用克莱姆法则计算线段交点

    E. Covered Points 利用克莱姆法则计算线段交点.n^2枚举,最后把个数开方,从ans中减去. ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算. #include ...

  8. Covered Points Count CF1000C 思维 前缀和 贪心

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

  9. Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...

随机推荐

  1. [洛谷P4124][CQOI2016]手机号码

    题目大意:给你两个$l,r$,求出$[l,r]$中符合要求的数,要求为至少有$3$个相邻的相同数字,且不可以同时出现$8$和$4$ 题解:数位$DP$ 卡点:无 C++ Code: #include ...

  2. 工具——SVN常用命令

    SVN一般都是团队合作做一个项目所需用到的,为了是版本的统一 ;1. Check out——从服务器端取得代码    把服务器资料库里存放的某个项目代码取出来,放到本地主机中,这个动作叫做“check ...

  3. Java 处理 XML 的三种主流技术及介绍

    Java 处理 XML 的三种主流技术及介绍 原文地址:https://www.ibm.com/developerworks/cn/xml/dm-1208gub/ XML (eXtensible Ma ...

  4. 使用Idea远程部署调试tomcat

    转自:http://blog.csdn.net/jane1229/article/details/52402119 远程服务器的配置: 1.在远程服务器安装jdk和tomcat 2.配置环境变量 PA ...

  5. Lucene4.6 把时间信息写入倒排索引的Offset偏移量中,并实现按时间位置查询

    有个新的技术需求,需要对Lucene4.x的源码进行扩展,把如下的有时间位置的文本写入倒排索引,为此,我扩展了一个TimeTokenizer分词器,在这个分词器里将时间信息写入 偏移量Offset中. ...

  6. php2go - Go 实现 PHP 常用内置函数

    [转]http://www.syyong.com/Go/php2go-Use-Golang-to-implement-PHP-s-common-built-in-functions.html 使用Go ...

  7. JVM 性能排查--汇总

    参考:http://blog.sina.com.cn/s/blog_61d758500102wnus.html

  8. 基于SSM框架web搜索功能的实现

    这里适合选用于jsp搭建的网站,数据库采用MySQL 一.HTML <div class="header_search"> <input type="t ...

  9. 如何完全禁用或卸载Windows 10中的OneDrive

    该功能占用很大的内存与CPU 详见http://os.51cto.com/art/201508/489371.htm

  10. Highcharts制作图片表设置线条颜色和粗细

    Chart:图表区选项 Chart图表区选项用于设置图表区相关属性. 参数 描述 默认值 backgroundColor 设置图表区背景色 #FFFFFF borderWidth 设置图表边框宽度 0 ...