B - Foosball Dynasty

桌游游戏

题意就是告诉你Balaji and his coworkers like to play Foosball on their lunch break. Foosball is a game typically
played by 2 players (individual matchup) or 4 players (team play). However, due to the increasing
interest and availability of coworkers, Balaji has created a new variation that supports 5 or more
players. Each individual point is played by four players: two on the White team and two on the
Black team.
Figure B.1
The remaining players wait in line for their turn to play. On each point, the players on the scoring
team switch positions (e.g., if White scores the point, then the White Offense player becomes the
White Defense player, and vice versa). The Offense player of the team that lost the point becomes
the Defense player of the same team, while the Defense player of the team that lost the point goes
to the back of the line and waits for their next chance to play. The person at the front of the line
becomes the new Offense player of the team that lost the point.
Based on these rules, a team that continues scoring consecutive points gets to keep playing together
(swapping positions with each other after each point) until the other team breaks the streak. Each
such streak of points creates a dynasty for the winning team. Dynasties can be short-lived (a single
point) or long-lived, but they are always broken when the opposing team scores a point. The
“winners" of this variation of foosball are the players that can create the longest dynasty.
ECNA 2016 Problem B: Foosball Dynasty 3
Input
Input begins with a line containing an integer n representing the number of players (5 ≤ n ≤ 10).
The next line contains the n names of all participating players. The first four are the names of the
four players who initially arrive at the table (in that order): the first person to arrive starts at White
Offense, the second starts at Black Offense, the third starts at White Defense, and the fourth starts at
Black Defense. The remaining players get in line to wait for their turn. The final input line contains
a non-empty string indicating which side scored each point, with a White team point represented by
‘W’ and a Black team point represented by ‘B’. The maximum length of this string will be 1000.
Output
Display the team that has achieved the longest dynasty. If more than one team ties for the record,
then display each of these teams in chronological order, one team per line. When displaying a team,
names should be displayed in the order in which the players arrived at the table for that team. Note
that it is possible for the same team to appear more than once in the output, potentially with the
player names in a different order.
Sample Input 1 Sample Output 1
6
Balaji David Alex Scott Andrew Ravi
WWBWBBWBW
Balaji Alex
Andrew David
Sample Input 2 Sample Output 2
6
Amy Jinu Kasey Sarah Sheetal Julia
BBBBB
Jinu Sarah
ECNA 2016 Problem B: Foosball Dynasty


题比较乱,大致就是给出一种规则然后给出一些人名然后让你模拟游戏的过程,输出连续获胜记录保持着的组的组员名单


直接模拟即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int n;
string a[15];
string B;
queue<string> q;
string w0,w1,b0,b1,c0,c1,d0,d1;
void init()
{
   c0 = w0 = a[0],c1 = w1 = a[2];
   d0 = b0 = a[1],d1 = b1 = a[3];
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    cin>>B;
    int len = B.length();
    vector<pair<string,string> >ans[len+1];
    init();
    for(int i=4;i<n;i++)
    q.push(a[i]);
    int w=0,b=0;
    for(int i=0;i<len;i++)
    {
        swap(w0,w1);
        swap(b0,b1);
        if(B[i]=='W')
        {
            w++;
            b=0;
            ans[w].push_back(make_pair(c0,c1));
            q.push(b0);
            d1 = b0 = q.front();
            d0 = b1;
            q.pop();
        }
        else
        {
            w=0;
            b++;
            ans[b].push_back(make_pair(d0,d1));
            q.push(w0);
            c1 = w0 = q.front();
            c0 = w1;
            q.pop();
        }
    }
    for(int i=len;i>=0;i--)
    {
        if(ans[i].size())
        {
            for(int j=0;j<ans[i].size();j++)
                cout<<ans[i][j].first<<" "<<ans[i][j].second<<endl;
            break;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值