Game Rank(NCPC 2016 大模拟)

题目:

The gaming company Sandstorm is developing an online two player game. You have been asked to implement the ranking system. All players have a rank determining their playing strength which gets updated after every game played. There are 25 regular ranks, and an extra rank, “Legend”, above that. The ranks are numbered in decreasing order, 25 being the lowest rank, 1 the second highest rank, and Legend the highest rank. 

Each rank has a certain number of “stars” that one needs to gain before advancing to the next rank. If a player wins a game, she gains a star. If before the game the player was on rank 6-25, and this was the third or more consecutive win, she gains an additional bonus star for that win. When she has all the stars for her rank (see list below) and gains another star, she will instead gain one rank and have one star on the new rank.

For instance, if before a winning game the player had all the stars on her current rank, she will after the game have gained one rank and have 1 or 2 stars (depending on whether she got a bonus star) on the new rank. If on the other hand she had all stars except one on a rank, and won a game that also gave her a bonus star, she would gain one rank and have 1 star on the new rank.

If a player on rank 1-20 loses a game, she loses a star. If a player has zero stars on a rank and loses a star, she will lose a rank and have all stars minus one on the rank below. However, one can never drop below rank 20 (losing a game at rank 20 with no stars will have no effect).

If a player reaches the Legend rank, she will stay legend no matter how many losses she incurs afterwards.

The number of stars on each rank are as follows:

• Rank 25-21: 2 stars

• Rank 20-16: 3 stars

• Rank 15-11: 4 stars

• Rank 10-1:   5 stars

A player starts at rank 25 with no stars. Given the match history of a player, what is her rank at the end of the sequence of matches?

Input:

The input consists of a single line describing the sequence of matches. Each character corresponds to one game; ‘W’ represents a win and ‘L’ a loss. The length of the line is between 1 and 10 000 characters (inclusive).

Output:

Output a single line containing a rank after having played the given sequence of games; either an integer between 1 and 25 or “Legend”.

题意:

“炉石传说”排位模拟,条件真的多啊,列出所有的条件慢慢来就ok了。

条件:

  1. 每个Rank的star的个数如上。
  2. 如果玩家Rank处于6-25之间,那么只要连赢3场及更多场,每次加2颗star,否则赢了只能加一颗star。
  3. 当玩家升至Rank后就不会再掉到Rank20以下,也就是说当玩家在Rank20+0star时输了比赛,并不会掉Rank。
  4. 当玩家在Rank Legend的时候,输赢将不会再产生影响。
  5. 当玩家处于Rank x + 0star 输掉比赛,玩家的段位变为Rank (x+1)+ full-1 star,full-1也就是下一个段位最大star数减一。

注意到以上条件开工写代码:

代码:

#include <bits/stdc++.h>
#define FRE() freopen("in.txt","r",stdin)
using namespace std;
const int maxn = 1e4+10;
typedef long long ll;

struct Player
{
    int rak;
    int star;
    Player()
    {
        rak = 25;
        star = 0;
    }
};

int judgeFullWin(int x,int star)//得到Rank上升后的star的个数
{
    if(x>=21 && x<=25)
        return star-2;
    else if(x>=16 && x<=20)
        return star-3;
    else if(x>=11 && x<=15)
        return star-4;
    else if(x>=1 && x<=10)
        return star-5;
}

int judgeFullLose(int r)//返回每个Rank对应的最大的star的个数
{
    if(r>=21 && r<=25)
        return 2;
    else if(r>=16 && r<=20)
        return 3;
    else if(r>=11 && r<=15)
        return 4;
    else if(r>=1 && r<=10)
        return 5;
}


int main()
{
    Player p;
    char str[maxn];
    scanf("%s",&str);
    int cw = 0;
    for(int i = 0; str[i]; i++)
    {
        if(str[i]=='W' && (p.rak>=1 && p.rak<=25))
        {
            if(p.rak>=6 && p.rak<=25)//6-25获胜
            {
                cw++;//连胜率
                if(cw>=3)
                {
                    int s = judgeFullWin(p.rak, p.star+2);
                    if(s > 0)
                    {
                        p.rak--;
                        p.star = s;
                    }
                    else
                        p.star+=2;
                }
                else
                {
                    int s = judgeFullWin(p.rak, p.star+1);
                    //printf("S: %d\n",s);
                    if(s > 0)
                    {
                        p.rak--;
                        p.star = s;
                    }
                    else
                        p.star++;
                }
            }
            else if(p.rak>=1 && p.rak<=5)
            {
                int s = judgeFullWin(p.rak, p.star+1);
                if(s > 0)
                {
                    p.rak--;
                    p.star = s;
                }
                else
                    p.star++;
            }
        }
        else if(str[i]=='L' && (p.rak>=1 && p.rak<=25))
        {
            cw = 0;//连胜率为0
            if(p.rak>=1 && p.rak<=20)
            {
                if((p.rak==20 && p.star == 0)||(p.rak==25 && p.star == 0))
                    continue;
                if(p.star==0)
                {
                    p.star = judgeFullLose(p.rak+1)-1;
                    p.rak++;
                }
                else
                    p.star--;
            }

        }
    }
    if(p.rak == 0)
        printf("Legend\n");
    else
        printf("%d\n",p.rak);

    return 0;
}
/*
样例输入:
WW
WWW 
WWWW 
WLWLWLWL 
WWWWWWWWWLLWW
WWWWWWWWWLWWL
样例输出:
25
24 
23
24
19
18
*/
View Code

猜你喜欢

转载自www.cnblogs.com/sykline/p/9755920.html