NC222157. CocktailWithPony
描述
输入描述
The first line of input contains a positive integer , which represents the number of test cases.Each test contains five positive integers and guarantee .The meaning is as shown in the statement.
输出描述
For each test data, output a positive integer in one line to indicate that the wolf needs several rounds to catch the pony.
示例1
输入:
1 10 3 1 4 8
输出:
4
说明:
The pony moves to position in the first round, and the wolf moves to position in the second round. In the third round, the little pony must move, so it can only move to position or . No matter which position it is, the wolf can catch up in the fourth round. So output .C++ 解法, 执行用时: 74ms, 内存消耗: 796K, 提交时间: 2021-05-26 00:12:30
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; int n,v1,v2,x1,x2; while(t--) { cin>>n>>v1>>v2>>x1>>x2; if(x1<x2) { x1=n-x1+1; x2=n-x2+1; } int cnt=1; while(true) { if(cnt&1) { if(x2==1&&x1==2) break; if(x2-v2>=1) x2-=v2; else if((v2-x2)%2==0) { x2=2; } else x2=1; } else { if(x1-x2<=v1) break; x1-=v1; } cnt++; } cout<<cnt<<endl; } }