1 solutions
-
0
C++ :
#include<bits/stdc++.h> using namespace std; int main(){ int x1,y1,x2,y2,t; cin>>x1>>y1>>x2>>y2; int r; //平移坐标 if(x1 >= x2){ x1 = x1 - x2; }else{ x1 = x2 - x1; } if(y1 >= y2){ y1 = y1 - y2; }else{ y1 = y2 - y1; } //看看在不在x或者y轴上 if(x1 == 0){ r = y1 + 1; } else if(y1 == 0){ r = x1 + 1; } else { //求x1和y1的最大公约数+1就是经过的交叉点的数量 while(x1 % y1 != 0){ t = x1 % y1; x1 = y1; y1 = t; } r = y1 + 1; } cout<<r<<endl; }
- 1
Information
- ID
- 10296
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By