Description
Given two pointsAandBon theX-Yplane, output the number of the lattice points on the segmentAB. Note thatAandBare also lattice point. Those who
are confused with the definition of lattice point, lattice points are those points which have bothxandyco-ordinate as integer.
For example, forA (3, 3)andB (-1, -1)the output is5. The points are:(-1, -1), (0, 0), (1, 1), (2, 2) and (3, 3).
Input
Input starts with an integerT (≤ 125), denoting the number of test cases.
Each case contains four integers,Ax, Ay, BxandBy. Each of them will be fit into a32bit signed integer.
Output
For each test case, print the case number and the number of lattice points betweenAB.
题目很简单,就是让你求两个整数点连成的线段上的整数点(包括两端)有多少个
比如(1,1)(3,3)之间的点有(1,1),(2,2),(3,3)三个点;
看到这个题我想用斜率来做,结果做了两个小时还是不对,后来才知道思路不对,求下公约数就能出来;
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
int tCase,t=1;
long long x1,y1,y2,x2;
scanf("%d",&tCase);
while(tCase--)
{
scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
printf("Case %d: %lld\n",t++,(long long)__gcd(abs(y2-y1),abs(x2-x1))+1);
}
return 0;
}
分享到:
相关推荐
LightOJ
LightOJ-已解决代码我所有的Light Online Judge的解决问题代码。
LightOJ-solutions
轻描淡写 像Codeforces编辑模式一样在lightoj上发表社论!
问题教程:一个包含有关LightOJ问题的教程的存储库
光OJ 收集我在发现的一些问题的解决方案
已解决的编程问题 Online Judges 这个存储库包含我解决的各种在线法官的编程问题的解决方案,即 UVa、Topcoder、Codeforces、Hackerrank、LightOj、Spoj、Project Euler 等。
leetcode 2 和 c 动态规划 动态规划相关问题的解答。 这些问题来自各种在线评委,包括 、 、 等。 解决方案是用 C++ 编码的。 —— —— —— —— —— —— —— —— —— —— —— —— ...——
这是乔杜里医学博士。 伊斯玛姆·拉赫曼(Ishmam Rahman) :closed_mailbox_with_raised_flag: 联络我: ... LightOJ: ://lightoj.com/user/ishmam64 脸书: : 目标:使自己在新技术的海洋中立足,在这里我可
race_words = [“后缀数组”,“前缀特里”,“动态编程”,“竞赛”,“ codeforces”,“编程”,“竞争性编程”,“算法”,“数据结构”,“ codeforces”,“ light oj”,“ lightoj”,“ spoj”,“堆栈”,...
描述在这里,您可以从uva,lightoj,spoj,timus等不同的在线法官那里找到我解决的问题。
解析编程问题,并将其发送给CHelper插件以实现IntelliJ IDEA。 竞争性伴侣解析程序...-HackerRank-HDU在线法官-Kattis-LightOJ-NYTD在线法官-PEG法官-POJ-QDUOJ-Timus-URI在线法官 支持语言:English (United States)
leetcode中国 数据结构和算法编码 议程 :balloon: 不是为了比赛,而是为了训练和兴趣。 Python3 你可以在这里找到我的 LeetCode 解决方案:(等待打开) ...LightOJ 1012 --- dfs transform 13. HDU 1495 --- compl
测试程序TestProgram 是针对竞争性编程程序(即 Codeforces、lightOJ、OmegaUp 等)的专用测试工具。 当我们解决问题时,我们必须非常小心,并致力于解决所有可能的情况。 我们的解决方案在登顶前正确解决的测试用例...
开心农场java源码AA Noman Ansary 你好呀! 我的名字是AA Noman Ansary 。 但我更喜欢被称为Showrav...问题解决:LightOJ。 代码部队。 蒂姆斯。 紫外线。 成就 以下是我的一些显著成就: BRAC 大学副校长证书。 (2019)
problemSolving
这个仓库是关于什么的 创建该存储库是为了组织与数据结构和算法有关的问题的解决方案。 并且,如果可能的话,为学习与数据结构和算法有关的各种概念提供一种更简单的方法。 以下评委使用的问题 ...