第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 B.XTL‘s Chessboard(思维)

题目链接: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;
}

猜你喜欢

转载自blog.csdn.net/Sankkl1/article/details/109433510