LightOJ 1077 - How Many Points? (线段整数点个数)
来源:互联网 发布:请叫我威廉三世知轩 编辑:程序博客网 时间:2024/05/16 08:32
1077 - How Many Points?
PDF (English)StatisticsForum
Time Limit: 0.5 second(s)Memory Limit: 32 MB
Given two points A and B on the X-Yplane, output the number of the lattice points on the segmentAB. Notethat A and B are also lattice point. Those who are confused withthe definition of lattice point, lattice points are those points which havebothx and y co-ordinate as integer.
For example, for A (3, 3) and B (-1, -1) theoutput is5. 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,Bxand By. Each of them will be fit into a 32bit signed integer.
Output
For each test case, print the case number and the number oflattice points betweenAB.
Sample Input
Output for Sample Input
2
3 3 -1 -1
0 0 5 2
Case 1: 5
Case 2: 2
题意:给出一条线段的两个端点,求在这条线段上有多少个整数点
思路:水题,整数点个数为gcd(abs(x1-x2),abs(y1-y2))+1。。。
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 1010100#define LL long long#define ll __int64#define INF 0x7fffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)#define eps 1e-10using namespace std;LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}int lcm(int a,int b){return a/gcd(a,b)*b;}LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}//headint main(){ int t,i,j; LL x1,x2,y1,y2; int cas=0; scanf("%d",&t); while(t--) { scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2); LL ans=gcd(abs(x1-x2),abs(y1-y2)); printf("Case %d: ",++cas); printf("%lld\n",ans+1); } return 0;}
0 1
- LightOJ 1077 - How Many Points? (线段整数点个数)
- LightOJ 1077 How Many Points?
- lightoj 1077 - How Many Points? 最大公约数
- LightOJ 1077 How Many Points? (变种gcd)
- 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?
- cf#334-C. Alternative Thinking-规律题
- 单点登录系统cas资料汇总
- 【HDU3068】最长回文【Manacher】
- 单点登录方案的比较和选择
- 【URAL1297】Palindrome【Manacher】
- LightOJ 1077 - How Many Points? (线段整数点个数)
- 解决中文文件名显示乱码的问题
- python乱码小记
- 11款开放中文分词引擎大比拼
- bzoj 2055 80人环游地球(上下界费用流)
- 对于支付宝进军社交的看法
- 阿里分布式数据库服务实践
- Nginx简介
- App架构设计经验谈:接口的设计