題目鏈接:https://ac.nowcoder.com/acm/contest/8688/B
題目描述
Xutianli is a perfectionist, who only owns “Good Chessboard”.
A well-known definition to the Good Chessboard is that there exists two integers u,v which satisfies ux+vy=1+u+v, with the given length x and width y.
Once Zjx came to XTL’s home and brought a small ball. This ball was originally used to hit XTL, because he always touches fish under the pan pond every day(touch fish means dereliction of duty). However, seeing that XTL had really worked conscientiously and enthusiastically, Zjx felt very guilty and gave the ball to XTL as a gift.
After that is a boring time of two boys. XTL design a game based on his “Good Chessboard” Prescribed procedure is as follows.
On the rectangular chessboard composed of squares of X * Y, select a left or bottom grid as the starting grid, and then place a ball in the center of the grid. The diameter of the ball is the length of the side of a grid on the chessboard. Push the ball up 45 degrees to make it roll on the chessboard. When the ball touches the edge of the board, it will bounce back. The rebound rule is: the rebounding route is perpendicular to the original route, just as the reflection of light on a plane mirror. If the ball attaches the corner, it will roll back according to the original route. The ball moves on the chessboard from the starting grid (if the starting grid is in the upper left or lower right corner, it will rebound immediately at the beginning) until it returns to the starting grid.
XTL will take a piece of his cherished chessboard from his storeroom, place the ball, and kick it obliquely up 45 degrees to let Zjx count the number of grids the ball has passed through for odd number of times and tell XTL the answer after the ball stops moving.
Zjx dislikes the game as boring. He wants to do some homework about the Lie Algebroid connection, to discuss some properties about commutative group, to find out some new Mathematical technique in order to improve the effectiveness and robustness of traditional algorithms, and finally send several SCI articles randomly for the sake of postgraduate recommendation.
Smart as you, can you tell him the solution OF this extremely depressing Question?
輸入描述:
The input consists of a single test case specified with two lines. The first line contains four integers x, y, a and b, where x is the length of the chessboard, y is the width of chessboard, a,b is the coordinate of the starting grids(x,y>=2,x*y<=1000000000)
輸出描述:
The output consists of a single integer, representing the number of grids the ball has passed through for odd number of times.
示例1
輸入
13 6 1 5
輸出
2
分析
如果開始點在左上角或者右上角,那么答案肯定是 0 ;如果棋盤是個正方形,并且起點在左下角,那么答案肯定是 1 ,如果在其他地方(除了左上角和右上角),那么答案也是 1 (因為最后會在不碰到角落的情況下回來);其他情況,答案肯定是 2 ,
因為題目的資料比較水,直接輸出 2 也能過,,
代碼
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll x,y,a,b;
cin>>x>>y>>a>>b;
if((a==x&&b==1)||(a==1&&b==y))
{
printf("0\n");
}else if(a==1&&b==1&&x==y)
{
printf("1\n");
}else{
if(x==y)
{
printf("%lld\n",2*x-2);
}else{
printf("2\n");
}
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/200466.html
標籤:其他
下一篇:網路基礎:TCP擁塞控制
