// 扩展欧几里得算法 
// 先求出一个解 再求出区间 [x1,x2]有几个整数符合条件
// 需要注意的是 水平和垂直2种情况的处理 还有正数和负数取整的细微差别
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MOD 1000000007
#define maxn 1000010
#define maxm 48010
#define LL long long
LL ax,ay,bx,by;
LL a,b,c;
LL d,x,y;
void extendGcd(LL a,LL b){
if(b==){
d=a;
x=;
y=;
}else{
extendGcd(b,a%b);
LL t=x;
x=y;
y=t-a/b*y;
}
}
LL lt(double p){
if(p>){
LL x=p+0.05;x=x*;
LL y=(p+0.05)*;
if(x==y) return x/;
return x/+;
}
else{
return (LL)(p-0.05);
}
}
LL rt(double p){
if(p>=)
return (LL)(p+0.05);
else {
LL x=p-0.05;x=x*;
LL y=(p-0.05)*;
if(x==y) return x/;
return x/-;
}
}
LL get(double d){
if(d>=) return (d+0.05)*;
else return (d-0.05)*;
}
int main(){ int T;
double x1,y1,x2,y2;
LL ax,ay,bx,by;
LL a,b,c;
scanf("%d",&T);
while(T--){
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
ax=get(x1);ay=get(y1);
bx=get(x2);by=get(y2);
if(ay==by){
if(ay%) { printf("0\n");continue;}
LL lx=lt(min(x1,x2)),rx=rt(max(x1,x2));
if(lx==rx&&ay%){printf("0\n");continue;}
printf("%lld\n",rx-lx+);
continue;
}
else if(ax==bx) {
if(ax%) { printf("0\n");continue;}
LL ly=lt(min(y1,y2)),ry=rt(max(y1,y2));
if(ly==ry&&ax%){printf("0\n");continue;}
printf("%lld\n",ry-ly+);
continue;
} a=(ay-by)*;
b=(bx-ax)*;
c=(bx-ax)*ay-(by-ay)*ax; extendGcd(a,b);
if(c%d!=){printf("0\n");continue;}
x=x*(c/d);
LL m=b/d;
LL lx=lt(min(x1,x2)),rx=rt(max(x1,x2));
if(m<) m=-m;
x=x-(x-lx)/m*m;
x-=m;
while(x<lx)
x+=m;
LL k=(rx-x)/m;
while(x+k*m<=rx) k++;
printf("%lld\n",k);
}
return ;
}

uva 11768的更多相关文章

  1. UVA 11768 - Lattice Point or Not(数论)

    UVA 11768 - Lattice Point or Not option=com_onlinejudge&Itemid=8&page=show_problem&categ ...

  2. UVA 11768 Lattice Point or Not(扩展欧几里德)

    将直线转化为ax + by = c的形式,然后扩展欧几里得求在[x1, x2]之间的解 对直线与坐标轴平行的特判 调试了好长时间,注意: 1 正负数转化为整型的处理 2 注意判断有无解 #includ ...

  3. UVA 11768 - Lattice Point or Not

    首先本题需要用到扩展欧几里得算法…… 关于exgcd算法的一点简略证明: 那么,对于函数exgcd(a,b)=(d,x,y),其中d满足d=gcd(a,b); (x,y)满足ax+by=d; 则exg ...

  4. Lattice Point or Not UVA - 11768(拓展欧几里得)

    原文地址:https://www.cnblogs.com/zyb993963526/p/6783532.html 题意: 给定两个点A(x1,y1)和B(x2,y2),均为0.1的整数倍.统计选段AB ...

  5. UVa 11768 格点判定(扩展欧几里得求线段整点)

    https://vjudge.net/problem/UVA-11768 题意: 给定两个点A(x1,y1)和B(x2,y2),均为0.1的整数倍.统计选段AB穿过多少个整点. 思路: 做了这道题之后 ...

  6. UVA - 11768 Lattice Point or Not (扩展欧几里得)

    求一条线段上有多少个整点. 是道扩欧基础题,列出两点式方程,然后分四种情况讨论即可.但细节处理较多很容易写挫(某zzWA了十几发才过掉的). 由于数据精度较小,浮点数比较没有用eps,直接==比较了. ...

  7. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  8. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  9. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

随机推荐

  1. Relearning PHP (2) – php 的浮点数float

    Relearning PHP (2) – php 的浮点数float 暂无评论 php有很多坑,但是并不妨碍他是最好的语言.其他语言对于浮点数处理同样有问题,这应该是个“共有坑”.不信可以用googl ...

  2. 安装numpy/scipy/scikit-learn的方法

    安装numpy 和 scipy sudo yum install lapack lapack-devel blas blas-devel   sudo yum install numpy.x86_64 ...

  3. Android 虚拟机安装SD卡

    在cmd命令行下,进入platform-tools目录下.   1.创建sdcard   mksdcard -l mycard 256M E:\android\myCards\mysdcard.img ...

  4. Java并发包中常用类小结(一)

    从JDK1.5以后,Java为我们引入了一个并发包,用于解决实际开发中经常用到的并发问题,那我们今天就来简单看一下相关的一些常见类的使用情况. 1.ConcurrentHashMap Concurre ...

  5. Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace

    被这个问题折磨着很久:参考: http://have23.iteye.com/blog/1340777 (cfx 与 spring 整合的时候出现的问题: org.springframework.be ...

  6. map的详细用法

     map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时 ...

  7. android休眠唤醒流程2

    android系统一段时间没有操作,    屏幕(screen)将从高亮(bright)变为暗淡(dim),如果再过段时间还是没有操作,屏幕(screen)从暗淡(dim)变为关闭(off).这时,系 ...

  8. PCA understanding

    PCA understanding 我们希望获取玩具的位置,事实上我们只需要知道玩具在x轴的位置就可以了(但现实不知道).我们利用三个坐标轴,获取了2*3维度的数据,现实中我们如何通过分析六维度数据来 ...

  9. python3.4安装suds

    使用suds访问webservice十分方便 python3.x安装suds会报错“No module named client” 在stackoverflow上找到了替代方法,安装suds-jurk ...

  10. IIS 无法打开页面,只能重启的问题

    最终解决方案: 要变通解决此问题,启用 EnableAggressiveMemoryUsage 注册表项在注册表中.当启用了 EnableAggressiveMemoryUsage 注册表项 Http ...