求解蜗蜗棋 别时间超限

间限制:1 s
空间限制:1024 MB
蜗蜗棋
c++ 用二分
蜗蜗棋里有一颗棋子,一开始出现在数轴上等于 x 的位置。

对于每一步,假设当前棋子的位置为 c,如果 c<k,那么蜗蜗会把棋子挪到位置 c+y,否则蜗蜗会把棋子挪到位置 c−z。

给定 x,y,z,k,s,请问 s 步以后棋子在什么位置?

输入格式
第一行一个整数 test 表示数据组数。

对于每组数据,一行五个整数 x,y,z,k,s。

输出格式
对于每组数据,输出一行一个整数表示棋子最后的位置。

样例输入
2
1 2 3 3 2
1 2 3 3 3
样例输出
0
2
数据规模
对于 30% 的数据,保证 1≤test≤100,1≤s≤105。

对于 100% 的数据,保证 1≤test≤105,1≤x,y,z,k,s≤109。

小数据,模拟可以做出

img

#include<bits/stdc++.h>
using namespace std;
int main() {
    int test;
    cin>>test;
    while(test--){
        int x,y,z,k,s;
        cin>>x>>y>>z>>k>>s;
        while(s--){
            x<k?x+=y:x-=z;
        }cout<<x<<endl;
    }
    return 0;
}
 

这题数据较小,可以模拟做出来