Problem 3036 --Halt Hater

3036: Halt Hater

"
Time Limit $4$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Cuber QQ has recently won a million dollars and bought a new car. He is now driving in the Infinite City and he doesn't want his car to stop, ever! 

The Infinite City, looks like an infinite grid, with infinite streets built at all possible xx's and yy's when they are integers. The following picture, looks like part of this city. (The picture is downloaded from a webpage, which is certainly not describing the Infinite City.) 

There are traffic lights installed on every crossings. Just like what Chinese people usually do, the traffic lights only show signals for left and straight and you can always turn right regardless of the traffic light. The estimate time of waiting for a left turn is aa, at all crossings; and the time of waiting for a straight is bb

Cuber QQ is now driving from (0,−1)(0,−1) to (0,0)(0,0), about to entering the crossing at (0,0)(0,0). At a crossing, he can choose to go straight, turn left or turn right. He wishes to go to (x,y)(x,y), but here is a weird request: he wants to have the least estimated traffic light waiting time. In other words, he doesn't care whether he has to drive a long way, or he has to burn a lot of gas, all he wants is to wait as little as possible. 

Note that Cuber QQ doesn't have to wait for the traffic light at (x,y)(x,y); he also doesn't care from which direction he enters (x,y)(x,y)


The first line of the input contains an integer tt (1≤t≤100 0001≤t≤100 000). 

Then follows tt test cases, each containing aabbxxyy (1≤a,b≤1091≤a,b≤109−109≤x,y≤109−109≤x,y≤109|x|+|y|>0|x|+|y|>0), space separated. 
For each test case, output one integer as the answer.
4
9 1 0 2
2 1 8 0
2 3 3 3
1 1 -1 -1
2
7
6
1

推荐代码 查看3036 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$197 $ms] 淡意的温柔 591118 2020-06-06 08:10:34
内存最少[$0 $KB] 淡意的温柔 591118 2020-06-06 08:10:34
第一AC 淡意的温柔 591118 2020-06-06 08:10:34
第一挑战 淡意的温柔 591118 2020-06-06 08:10:34

赛题来源/所属竞赛 2019 Multi-University Training Contest 7 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛