2016 Al-Baath University Training Camp Contest-1 G
Description
The forces of evil are about to disappear since our hero is now on top on the tower of evil, and all what is left is the most evil, most dangerous monster! The tower has h floors (numbered from 1 to h, bottom to top), each floor has w rooms (numbered from 1 to w, left to right) composing a row. The monster stands in one of the ground floor (floor number 1) rooms (the room number d where 1 ≤ d ≤ w). Our hero stands in the top-left room of the tower. The only way for our hero to kill the evil monster is to throw down one of his power stones diagonally to the right. The stone will keep moving diagonally through the tower's rooms until it hits the right border of the tower, then it will change its direction to move down diagonally to the left until it hits the left border of the tower, then it will change its direction again and so on. This stone stops when it reaches the ground floor, if it stopped in the room of the monster, the monster is dead, otherwise the monster is still alive and the forces of evil will rise again! Help our hero to determine whether the stone will kill the monster or not!
The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. Each of the following lines contains a test case and consists of a three space-separated integers h, w and d denoting the height of the tower, the width of the tower and the number of room containing the monster. (1 ≤ d ≤ 109), (2 ≤ h, w ≤ 109).
For each test case print a single line: 'Yes' if the monster will be killed and 'No' otherwise.
5
9 4 2
9 4 3
5 4 3
10 2 1
10 2 2
No
Yes
Yes
No
Yes

In the first test case, the path of the power stone is colored in red. However the dragon is in the room denoted with D, so the monster is still alive and the answer is 'No'.
题意:见图
解法:找规律,这里以2*w-2作为一个循环,循环里面以最高点为对称
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include<bits/stdc++.h> using namespace std; int main() { int t,w,h,d; cin>>t; while (t--) { cin>>h>>w>>d; int num=2*w-2; int mod=h%num; //cout<<h%num<<endl; if (mod>w) { mod=2*w-mod; } else if (mod==0) { mod=2; } if (mod==d) { cout<< "Yes" <<endl; } else { cout<< "No" <<endl; } //cout<<mod<<endl; } return 0; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~