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

特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个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. 【BZOJ 1407】[Noi2002]Savage ExGCD

    我bitset+二分未遂后就来用ExGCD了,然而这道题的时间复杂度还真是玄学...... 我们枚举m然后对每一对用ExGCD判解,我们只要满足在最小的一方死亡之前无解就可以了,对于怎么用,就是ax+ ...

  2. Elasticsearch报错

    [2018-07-12T10:32:47,642][INFO ][o.e.b.BootstrapChecks ] [VfCcJIq] bound or publishing to a non-loop ...

  3. C语言一些常用的功能

    1.测试运行时间: #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { clock ...

  4. CentOS 安装 debuginfo-install

    安装debuginfo相关的包步骤如下: 1. 修改文件/etc/yum.repos.d/CentOS-Debuginfo.repo中的enabled参数,将其值修改为1 2. 使用命令: yum i ...

  5. Docker Community Edition for CentOS

    Docker CE for CentOS Docker CE for CentOS distribution is the best way to install the Docker platfor ...

  6. 固定width但是有间隔

    <!DOCTYPE > <html> <head> <title></title> <meta name="name&quo ...

  7. 怎样在WPS上实现代码语法高亮

    转载自:http://www.cnblogs.com/yuphone/archive/2009/12/13/1622901.html 小時不識月 Stupid & Hungry 本文列举两种可 ...

  8. [Python]简单的外星人入侵游戏

    alien_invasion.py: import sys import pygame from setting import Settings from ship import Ship impor ...

  9. 纯手工 CheckboxTree 实现

    数据结构及页面显示格式: INSERT INTO AS_CombRules VALUES('', '', '', '', '', '', '') 实现 CheckboxTree 功能: html代码: ...

  10. Vue项目中引入外部文件(css、js、less)

    例子中css文件采用bootstrap.css,js文件采用jQuery,less文件用less.less(自定义文件) 步骤一:安装webpack cnpm install webpack -g 步 ...