2016 NCPC Game Rank(模拟)
来源:互联网 发布:nginx docker 负载均衡 编辑:程序博客网 时间:2024/05/21 02:22
G: Game Rank
时间限制: 1 Sec 内存限制: 64 MB提交: 39 解决: 7
[提交][状态][讨论版]
题目描述
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?
输入
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 a single line containing a rank after having played the given sequence of games; either an integer between 1 and 25 or “ Legend ”.
样例输入
WW
样例输出
25
题意:有Legend和1-25共26个等级,每赢一局得到一个星星,如果连赢三局及以上并且等级在6-25之间可多得到一个星星,超过一定星星升级。输了并且在等级1-20,会失去一个星星,如果星星为负数并且在Legend和19之间会降级。
思路:
官方题解貌似:
import java.util.Scanner;import java.util.stream.IntStream;public class GameRank_Jimmy { public static void main(String[] args) { int starsPerRank[] = IntStream.range(0, 26).map(rank -> Math.min(5, 6 - (rank - 1) / 5)).toArray(); String s = new Scanner(System.in).next(); int rank = 25, stars = 0, cw = 0; for (int i = 0; i < s.length() && rank > 0; i++) { if (s.charAt(i) == 'W') { stars++; if (rank > 5 && ++cw >= 3) stars++; if (stars > starsPerRank[rank]) { stars -= starsPerRank[rank]; rank--; } } else { cw = 0; if (rank <= 20) { stars--; if (stars < 0) { if (rank == 20) { stars = 0; } else { rank++; stars = starsPerRank[rank] - 1; } } } } } System.out.println(rank == 0 ? "Legend" : rank); }}
0 0
- 2016 NCPC Game Rank(模拟)
- NCPC 2016 Game Rank(纯模拟)
- 【模拟】NCPC 2014 D Dice Game
- NCPC 2016 Fleecing the Raffle(推导)
- Problem G. Game Rank---Urozero Autumn Training Camp 2016-Day 1||简单模拟
- 【模拟】NCPC 2014 E ceremony
- 【模拟】NCPC 2014 K Train passengers
- NCPC 2016 A Artwork(并查集)
- Game(bc模拟题)
- HDU 5523 Game(模拟)
- ZJU1024-Calendar Game(模拟)
- HDU 5097 Page Rank(模拟,矩阵运算)
- [ACM] HDU 5131 Song Jiang's rank list (模拟)
- HDOJ 题目5097 Page Rank(矩阵运算,模拟)
- hdu 5131 Song Jiang's rank list(模拟)
- rank()
- poj 1666 : Candy Sharing Game (模拟)
- J - Candy Sharing Game(模拟题)
- 网络编程
- HTML 13 表格
- poj 2777 Count Color(位运算+线段树区间更新 可用bitset记录)
- Problem 38 Pandigital multiples (set + vector)
- Swift3.0 popToViewController 的使用
- 2016 NCPC Game Rank(模拟)
- c++实现日期类(class Date) 构造函数 拷贝构造 操作符重载(输入输出 比较操作 算数运算 自增自减)
- Leetcode #343 Integer Break
- 优化php效率,提高php性能的一些方法:
- C# socket学习--IPAddress、IPEndPoint、DNS
- Python 包管理工具解惑
- 页面自动适应屏幕的宽度
- caa二次开发的安装
- phpStorm更新后配置svn无法使用