第 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;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值