列表

详情


NC232088. If I Catch You

描述

square loop for n=6:

Liola and Eastred are playing a chasing game on a square loop which consists of 4n-4 grids, the size of the square is . Both Liola and Eastred can only move clockwise. In the beginning, Liola is at the upper right corner, and Eastred is at the bottom left corner.
The game is played in rounds, each round performs the following steps in order:
  1. Liola places a trap at his current position. Eastred can't move to the grids with traps, but Liola ignores these traps.
  2. Liola moves 2 or 3 grids.
  3. Eastred moves 1,2,3, or 4 grids.
At any time (even if a round is not over), the game is over if it meets any one of the following conditions:
  • If all the grids that Eastred can move have traps, Eastred can't move, Liola wins.
  • If Liola and Eastred are at the same grid, Eastred catches Liola, Eastred wins.
Both Liola and Eastred will play optimally. Can Eastred win? If he can, you should find the minimum number of rounds Eastred takes to win. In addition, If Liola can't win, he will try to make the number of rounds as large as possible.

输入描述

The first line contains an integer t  --- the number of test cases.
Each test case is described by one integer n --- the side length of the square loop.

输出描述

For each test case, output an integer in one line --- If Eastred loses, output -1. Otherwise, output the minimum number of rounds Eastred takes to win.

示例1

输入:

2
1
2

输出:

0
1

说明:

In test case 1, before the first round, Liola and Eastred are at the same grid. So Eastred catches Liola immediately, Eastred wins in 0 round.
In test case 2, the position of Liola and Eastred before the first round is as follows:



In the first round, Liola has two choices, go to ③ or ④. If he goes to ③, he will be caught immediately. So Liola places a trap at ① and goes to ④. We use X to represent the trap.



After Eastred moves 1 grid clockwise, Liola and Eastred are at the same grid, Eastred catches Liola, Eastred wins in 1 round.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 6ms, 内存消耗: 396K, 提交时间: 2021-12-20 19:23:43

#include <bits/stdc++.h>
using namespace std;
int n,t;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        cout<<max(2*n-3,0)<<endl;
    }
}

上一题