Codeforces 1036E. Covered Points
又一次写起了几何。。。。
特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个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的更多相关文章
- Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】
<题目链接> <转载于 >>> > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...
- CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)
https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖 ...
- codeforces 1000C - Covered Points Count 【差分】
题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...
- C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)
C - Covered Points Count CodeForces - 1000C You are given nn segments on a coordinate line; each end ...
- Educational Codeforces Round 46 C - Covered Points Count
C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...
- Covered Points Count(思维题)
C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- EDU 50 E. Covered Points 利用克莱姆法则计算线段交点
E. Covered Points 利用克莱姆法则计算线段交点.n^2枚举,最后把个数开方,从ans中减去. ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算. #include ...
- Covered Points Count CF1000C 思维 前缀和 贪心
Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count
Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...
随机推荐
- Numpy array学习笔记
- dns服务 很多问题,后续再研究
慕课网:http://www.imooc.com/video/5220 参考:http://jingyan.baidu.com/article/870c6fc32c028eb03fe4be30.htm ...
- 用JQuery的$.getJSON发起跨域Ajax请求
jQuery中常用getJSON来调用并获取远程的JSON字符串,将其转换为JSON对象,如果成功,则执行回调函数.原型如下: jQuery.getJSON( url, [data], [callba ...
- yaf学习网站
http://www.01happy.com/php-yaf-ext-business/
- zigbee ---- profile 和 cluster
在zigbee规范中,引入了profile, cluster的概念.具体说来,假设规范一个profile(可以理解成一套规定),这个profile用来规范智能家居领域的相关产品都要满足那些要求,那么h ...
- ansible+docker
1.准备镜像: 1007 docker run -itd --name client2 ff37bc5ab732 1008 docker run -itd --name client ff37bc5a ...
- Patch Windows with SSM on AWS
ec2ssmupdate https://docs.amazonaws.cn/systems-manager/latest/userguide/systems-manager-patch.htmlht ...
- (转)Python中实现带Cookie的Http的Post请求
转自crifan: http://www.crifan.com/python_http_post_request_with_cookie/ . . . .
- codeforce C. Okabe and Boxes
题目传送门 这道题 每次删除一个点 那么这个点必然在栈里面 那么如果堆顶不是他 我们就需要一次操作使得堆合理 这时我们可以把他删除然后把他下面的点打个标记表示这下面的点以后想怎么排就怎么排以后都不需要 ...
- 意想不到的chrome调试功能
没想到chrome的功能如此强大,绝非仅能使用console.log而已,碰到如此好文必定收藏,感谢大神,本文原创地址为:http://www.cnblogs.com/Wayou/p/chrome-c ...