博客
关于我
LightOJ - 1077 How Many Points
阅读量:793 次
发布时间:2023-01-31

本文共 654 字,大约阅读时间需要 2 分钟。

给你两个格点,求以它们为端点的线段上有多少个格点

答案为gcd(abs(x1-x2), abs(y1-y2)) + 1

1 #include 
2 #include
3 #include
4 #include
5 #define INF 0x3f3f3f3f 6 using namespace std; 7 typedef long long LL; 8 9 int T;10 LL x1, y1, x2, y2;11 12 LL gcd(LL a, LL b) {13 return b == 0 ? a : gcd(b, a % b);14 }15 16 int main() {17 scanf("%d", &T);18 for (int t = 1; t <= T; t++) {19 scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);20 printf("Case %d: %lld\n", t, 1 + gcd(abs(x1 - x2), abs(y1 - y2)));21 }22 return 0;23 }

 

转载于:https://www.cnblogs.com/xFANx/p/7521271.html

你可能感兴趣的文章
LeetCode哈希表+字符类的题目总结
查看>>
LeetCode地平线专场——第308场周赛题解
查看>>
LeetCode数据库题目汇总二(附答案)
查看>>
LeetCode新手指南:从零开始掌握算法挑战
查看>>
LeetCode智加科技专场——第207场周赛题解
查看>>
leetcode正则表达式匹配
查看>>
leetcode算法题解(Java版)-6-链表,字符串
查看>>
LeetCode经典——70.爬楼梯&&509.斐波拉契数列
查看>>
LeetCode蔚来专场——第208场周赛题解
查看>>
leetcode题解-买卖股票的最佳时机
查看>>
leetcode题解102-二叉树的层序遍历
查看>>
leetcode题解102-翻转二叉树
查看>>
leetcode题解104- 二叉树的最大深度
查看>>
leetcode题解108-将有序数组转换为二叉排序树
查看>>
leetcode题解118-杨辉三角
查看>>
leetcode题解131-分割回文串
查看>>
leetcode题解136-只出现一次的数字
查看>>
leetcode题解14-最长公共前缀
查看>>
leetcode题解151-翻转字符串里的单词
查看>>
leetcode题解153-寻找旋转排序数组的最小值
查看>>