跳棋游戏(模拟)

Board Game

时间限制: 1.000 Sec 内存限制: 128 MB

题目描述

Spend more time at home these days, you’ve decided to invent a board game, so, of course, you don’t get bored!!! Your game has n squares arranged in s cyclic order, numbered 0 through n-1.
Right after a player moves to square n-1, when they advance one more square, they go back to square 0. However, you don’t particularly like multiple players on the same square, so you’ve decided that if a player is to advance some number of squares, all squares that are passed with other players don’t count. Just like most board games, all players initially start on square 0, and to advance, they roll a pair of dice and advance the number of squares shown as the sum of the dice rolls. But, after each player’s initial move, she will never share a square with another piece,including other players who haven’t moved yet. Consider the game shown below (in the middle of the game) on a board with n= 12:

In this board, Player 1 (P1) is on square 7, Player 2 (P2) is on square 4, Player 3 is on square 10 and Player 4 is on square 1. Suppose that it’s Player 3’s turn and she rolls a sum of 7 on her two dice. The squares that would count are: 11, 0, 2, 3, 5, 6 and then 8, which is where she would move for the turn. Specifically, she jumped/skipped squares 1, 4 and 7 because these were occupied by Player 4, Player 2 and Player 1, respectively.
Counting manually has been too much of a hassle these days. Write a program to calculate where each player will end up after a series of rolls in a game.

The Problem
Given the number of squares on the game board, the number of players in the game, the number of moves that have been made, as well as the roll for each of those moves, calculate which game square each player is on after the completion of those moves

输入

The first line of input will contain a single positive integer, c (c≤ 20), representing the number of input cases to process. The input cases follow. The first line of each input case contains three space separated positive integers, n (6 ≤ n ≤ 100), representing the number of squares on the game board, p (2 ≤ p ≤ 10, p < n), representing the number of players in the game, and t (0≤ t ≤ 100), the number of turns played in the game so far. The second line of each input case contains t space separated integers, representing the sum of the dice of each of the t dice rolls, in the order that they were made. Players move in order, with Player 1 going first, then Player 2, etc. After player p, Player 1 goes again.

输出

For each case, output p lines, each with a single integer, such that the i th line is the square number (0-based) where the i th player is located on the game board after the t turns.

样例输入 Copy

12 4 7
2 3 8 10 4 9 7
10 5 2
5 6```
### 样例输出 Copy
```7
4
8
1
5
7
0
0
0```
### 提示
In the first sample, player 1 first moves to square 2. Then, player 2 moves to square 4 (moving 3 apaces). Then player 3 moves 8 squares to square 10 (skipping squares 2 and 4). Player 4 moves 10 squares, skipping squares 2, 4 and 10, landing on square 1, after completing a lap. Player 1 goes again advancing 4 squares, skipping over square 4, landing on square 7. Player 2 advances 9 squares, skipping over squares 7, 10 and 1, landing again on square 4. On the last move, Player 3 advances 7 squares, as described on the previous page, skipping over squares 1, 4 and 7 to land on square 8. 
In the second sample, only 2 turns occur before we print out where each player is. Player 1 advances to square 5, while player 2 advances 6 squares, skipping over square 5, landing on square 7. The other three players are on the starting square, square 0.

## 代码
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;cin >>t;
    while (t--)
    {

        int n,p,q;
        cin >> n >> p >> q;
        int v[105],dp[105];//dp记录玩家位置
        memset(dp,0,sizeof(dp));
        memset(v,0,sizeof(v));
        for(int i = 1;i <= q;++i)
        {//de(i);
            int temp;
            cin >> temp;
            int player_loc = dp[(i-1)%p + 1];//玩家位置
            v[player_loc%n] = 0;//标记取消
            while(temp--)
            {
                player_loc++;
                player_loc %= n;
                if((player_loc == 0 && i < p) || v[player_loc] == 1) temp++;//如果是有玩家占据就往后移动一个格子
                //de(player_loc);
            }
            v[player_loc%n] = 1;//标记
            dp[(i-1)%p + 1] = player_loc%n;//de(player_loc%n);

        }
        for(int i = 1;i <= p;++i) cout << dp[i] << endl;
    }
}

//把数据玩家p和q搞混了

posted @   bakul  阅读(1)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示