Kattis

Game Rank

/problems/gamerank/file/statement/en/img-0001.png
Picture by Gonkasth on DeviantArt, cc by-nd
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 2525 regular ranks, and an extra rank, “Legend”, above that. The ranks are numbered in decreasing order, 2525 being the lowest rank, 11 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 66-2525, 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 11 or 22 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 11 star on the new rank.

If a player on rank 11-2020 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 2020(losing a game at rank 2020 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 2525-2121: 22 stars

  • Rank 2020-1616: 33 stars

  • Rank 1515-1111: 44 stars

  • Rank 1010-11: 55 stars

A player starts at rank 2525 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 11 and 1000010000 characters (inclusive).

Output

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

Sample Input 1Sample Output 1
WW
25
Sample Input 2Sample Output 2
WWW
24
Sample Input 3Sample Output 3
WWWW
23
Sample Input 4Sample Output 4
WLWLWLWL
24
Sample Input 5Sample Output 5
WWWWWWWWWLLWW
19
Sample Input 6Sample Output 6
WWWWWWWWWLWWL
18

题意

25级升24级,要两颗星,但是不是两颗星满了升24,是3颗星才升级变成24级一星。然后24到23到……一直到20都是两颗星,然后3颗星 4颗星 5颗星,然后你20级以下是不掉级的,输了也不掉,如果你是20级0星不会掉星,但是20级一颗星就会掉,你掉级条件是,当前星数为0而且输了,那就掉级了,然后,他还有一个设定,如果在5级以下连胜三局或者以上,一局奖励两颗星,然后,一级是顶级,超过了一级就直接输出LEGEND,接下来那个人输成什么样都是LEGEND,其实就是炉石传说的规则

代码

#include<bits/stdc++.h>
using namespace std;
int k[30] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2};
char aa[11000];
int main() {
    int n;
    while (~scanf("%s", aa)) {
        n = strlen(aa);
        int ans = 25, b = 0;
        for (int i = 0; i < n; i++) {
            if (aa[i] == 'W') {
                b++;
                if (i > 1 && aa[i - 1] == 'W' && aa[i - 2] == 'W' && ans >= 6)b++;
                if (b > k[ans]) {
                    b -= k[ans]; ans--;
                }
            } else {
                if (ans > 20 || ans == 20 && b == 0) {
                    continue;
                }
                b--;
                if (b < 0) {
                    ans++; b = k[ans] - 1;
                }
            }
            if (ans == 0)break;
        }
        if (ans) {
            printf("%d
", ans);
        } else {
            puts("Legend");
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zhien-aa/p/6295947.html