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

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

  1. 第45届国际大学生程序设计竞赛(ICPC)银川站太原理工大学收获4枚奖牌

    第45届国际大学生程序设计竞赛(ICPC)银川站,由宁夏理工学院承办,于2021年5月15-16日在宁夏的石嘴山市进行. 太原理工大学在比赛中获得2银2铜共4枚奖牌的好成绩. 参加本次比赛的四个队,涵 ...

  2. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)(重现赛)

    第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)(重现赛) 导语 涉及的知识点 题目 C D G J M 参考文献 导语 日常的队内集训,开始的时候状态其实很好,但是到了后两题就出现了 ...

  3. 第45届国际大学生程序设计竞赛(ICPC)沈阳站太原理工大学收获1枚铜牌

    第45届ICPC沈阳区域赛,于2021年7月18日在东北大学南湖校区举行.太原理工大学2个队参加比赛,由20级中学没有学过编程的3名同学组成的队,首次参加现场赛并获得铜奖.

  4. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 题解(除了C、G之后补)

    整理的算法模板合集: ACM模板 这次比赛好多原题呀-(就是那种稍微拓展了一点的原题) 目录 A.Easy Equation B.XTL's Chessboard D.Pokemon Ultra Su ...

  5. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明),签到题HIL

    H. Hard Calculation 链接:https://ac.nowcoder.com/acm/contest/12548/H 来源:牛客网 题目描述 Hooray! It is the fir ...

  6. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(南京)签到题K Co-prime Permutation,L Let‘s Play Curling

    序 emmm因为没时间补题(虽然签到有四题),所以只能先放两个签到. 这是比赛链接:https://ac.nowcoder.com/acm/contest/10272 这是题解链接:2020年ICPC ...

  7. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明),签到题4题

    文章目录 H. Hard Calculation I. Mr. Main and Windmills L. Simone and graph coloring J.Parallel Sort 补题链接 ...

  8. 【第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛】Simone and Graph Coloring

    #include <bits/stdc++.h> using namespace std; const int maxn = 1000005, INF = 0x7f7f7f7f; int ...

  9. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明) AC(带悔贪心)

    下面两个题都是选择iii有个价值如果选择iii则不能选择i−1,i+1i-1,i+1i−1,i+1,让价值最大或最小 P1792 [国家集训队]种树 野心qwq 的博客 #include<bit ...

最新文章

  1. Sql Server 三种事务模式
  2. 【学习Python】的网站
  3. python生物数据分析师职业技能_数据分析行业各个职业需要的技能是什么?
  4. java 不取空值_Java:如何更优雅的处理空值?
  5. 异步 HttpContext.Current实现取值的方法(解决异步Application,Session,Cache...等失效的问题)...
  6. Servlet接收JSP参数乱码问题解决办法
  7. 中国智能手机行业的江湖事
  8. 华三H3C交换机如何配置和使用telnet远程登录设备
  9. 数字化营销怎么做?如何做好数字化营销?
  10. FPS 每秒传输帧数(Frames Per Second)
  11. 程序员求职全流程指南
  12. three.js物体移动以及相机的移动(位置以及旋转方位)
  13. css动画 翻开折叠生日贺卡
  14. On the Factory Floor: ML Engineering for Industrial-Scale Ads Recommendation Models笔记
  15. 自己动手搭建一个简单的网站
  16. SAP 制造商物料功能启用和配置过程
  17. Idea2019.3 启动报错 Failed to load JVM
  18. 安利8款超级好用的3D建模软件
  19. 华为OD机试 - 模拟商场优惠打折(Python)
  20. 证明多元函数极限不存在的一个解法

热门文章

  1. User limit of inotify instances reached or too many open files
  2. PHP基础知识之遍历数组-foreach
  3. 读书笔记:培训师必修课
  4. VMware 安装WordPress Turnkey Linux详细步骤
  5. 哪些项目适合敏捷方法?
  6. Android图形合成和显示系统---基于高通MSM8k MDP4平台
  7. 求解矩形的面积,求解梯形的面积
  8. 复杂可编程逻辑器件的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  9. 数据库性能问题总结--屡次发生的Oracle谓词越界
  10. Huggingface Transformers简约教程(二)