LightOJ 1077 How Many Points?
来源:互联网 发布:熊片数据库 安卓 编辑:程序博客网 时间:2024/05/16 09:46
Description
Given two points A and B on the X-Y plane, output the number of the lattice points on the segment AB. Note that A and B are also lattice point. Those who are confused with the definition of lattice point, lattice points are those points which have both x and y co-ordinate as integer.
For example, for A (3, 3) and B (-1, -1) the output is 5. The points are: (-1, -1), (0, 0), (1, 1), (2, 2) and (3, 3).
Input
Input starts with an integer T (≤ 125), denoting the number of test cases.
Each case contains four integers, Ax, Ay, Bx and By. Each of them will be fit into a 32 bit signed integer.
Output
For each test case, print the case number and the number of lattice points between AB.
Sample Input
2
3 3 -1 -1
0 0 5 2
Sample Output
Case 1: 5
Case 2: 2
比如(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 1077 How Many Points?
- lightoj 1077 - How Many Points? 最大公约数
- LightOJ 1077 How Many Points? (变种gcd)
- LightOJ 1077 - How Many Points? (线段整数点个数)
- light oj 1077 how many points?
- Light OJ 1077 - How Many Points?
- How Many Points? gcd
- How Many Zeroes? LightOJ
- How Many Points of Intersection?
- How Many Points of Intersection?
- How Many Points of Intersection?
- How Many Points of Intersection?
- LightOJ 1140 How Many Zeroes?
- LightOJ 1140How Many Zeroes?
- LightOJ 1140 How Many Zeroes?
- UVa 10790 How Many Points of Intersection?
- uva 10790 How Many Points of Intersection?
- uva 10790 - How Many Points of Intersection?
- easyUI Draggable
- 27.跳台阶问题
- hnu 12432 Bottom of the sea#矩形交
- struts2-jquery-plugin 2超链接标签和<s:url/>的搭配使用
- 欢迎加新浪微博: weibo.com/zhengkarl
- LightOJ 1077 How Many Points?
- 独立成分分析(Independent Component Analysis)
- 基于hadoop和hbase的youtube简单模拟源码分享
- MySQL的导入导出
- 直接在MFC中用Directshow Transform filter
- 给mac终端iTerm2配色
- 比较字符串
- hnu 12436 Force of thrust#水题
- 修改用户名和用户组名