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]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...
随机推荐
- 你试过不用if写代码吗?
我在教新手编程时,喜欢给他们一些小小的挑战,比如:不使用if语句(或者三元运算符.switch语句等)解决一些编程问题.这样做有什么意义吗?事实上,它可以迫使你从不同的角度寻找解决方法,也许可以找到更 ...
- [Leetcode] Binary tree maximum path sum求二叉树最大路径和
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...
- 用伪类实现一个div的宽度和高度是固定百分比
遇到一个题目:一个div宽度是固定百分比的情况下,如何设置高度是宽度的80% 看到题目的第一反应是用js控制,获取到div的宽度之后再用宽度的80%来设置div的高度,但是如何在不用js的情况下,只用 ...
- 忘记mysq rootl密码后解决办法
如果mysql正在运行,/etc/init.d/mysqld stop 启动mysql(无需输入密码):bin/safe_mysqld –skip-grant-tables & 在bin目录下 ...
- Virtualization solutions on Linux systems - KVM and VirtualBox
Introduction Virtualization packages are means for users to run various operating systems without &q ...
- maven工程开启jetty调试
转摘自:http://czj4451.iteye.com/blog/1942437 准备工作: a. 在pom.xml中配置jetty插件: <plugins> <plugin> ...
- Linux 下打包报错:enospc (no space left on device)
昨天打了个包,早上发现很多页面js加载404,一查原来打包的min文件夹下是空的,打包出错了 Error code: enospc du -sh * rm -f 文件名称 rm -rf 目录名称 前端 ...
- Android 网络编程--上传文件及相应的参数到服务器
之前一直在做SiteCheck的项目,所用到的知识大部分都涉及到网络编程方面,所以现在有时间先把它的使用方法及一些注意事项记录下来.在这里我用两种例子让大家了解它的使用方法: (1)上传图片及相应参数 ...
- C# 序列化原因 (转)
1.什么是序列化 序列化是将对象状态转换为可保持或传输的格式的过程,在序列化过程中,对象的公共字段和私有字段以及类的名称(包括包含该类的程序集)都被转换为字节流,然后写入数据流.与序列化相对 ...
- rest service技术选型
MySql workbench下载 http://dev.mysql.com/downloads/workbench/ 最好的8个 Java RESTful 框架 http://colobu.com/ ...