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

特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个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. 2017 Multi-University Training Contest - Team 3 Kanade's trio(字典树+组合数学)

    题解: 官方题解太简略了orz 具体实现的方式其实有很多 问题就在于确定A[j]以后,如何找符合条件的A[i] 这里其实就是要提前预处理好 我是倒序插入点的,所以要沿着A[k]爬树,找符合的A[i] ...

  2. [Leetcode] Remove duplicate from sorted list ii 从已排序的链表中删除重复结点

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  3. 微信小程序使用原生WebSokcet实现断线重连及数据拼接

    以前做小程序为了应急找了个插件去链接WebSokcet,文章传送门. 回过头在新项目中再次使用时出现了些许问题,不一一赘述.遂决定好好用一下原生的WebSokcet. 一.说明 1.小程序原生的Web ...

  4. PHP正则匹配与替换的简单例子

    PHP正则匹配与替换的简单例子,含一个匹配获取加租字体例子和一个匹配替换超链接的例子. 1.查找匹配 <b> 与 </b> 标签的内容: <?php $str = &qu ...

  5. 通过AWS的DHCP自动获取的IP地址是否会发生改变?

    针对您的问题,分析如下:1.在一个VPC内,通过AWS的DHCP自动获取的IP地址,在如何情况下会发生改变?例如我把vpc的内所有100个ec2实例全部关闭,再全部重新打开,是否会发生IP地址变化的情 ...

  6. mpvue基本使用

    ## 什么是mpvue ## - 美团开发使用vue语法开发小程序的前端框架 - 适用于vue语法开发 - 会调用部分小程序API ## 创建mpvue项目 ## 1. 必须安装node.js 2.  ...

  7. 【Foreign】染色 [LCT][线段树]

    染色 Time Limit: 20 Sec  Memory Limit: 256 MB Description Input Output Sample Input 13 0 1 0 2 1 11 1 ...

  8. [POJ2068]Nim解题报告

    Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones ...

  9. [bzoj3224]Tyvj 1728 普通平衡树——splay模板

    题目 你需要写一种数据结构支援以下操作. 插入元素. 删除元素. 查询元素的排名. 查询第k小的元素. 查询元素前趋. 查询元素后继. 题解 BBST裸题. 代码 #include <cstdi ...

  10. python3 生成器表达式

    生成器表达式 [i for i in range(100)] #列表解析 与列表解析的不同是,列表解析用中括号,生成器表达式用小括号 g = (i for i in range(1000)) #生成器 ...