F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Painting Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 456    Accepted Submission(s): 212


Problem Description
There is a paper strip divided into $n$ blank grids. For each $i(1\leq i < n)$, grid $i$ and $i+1$ are considered adjacent.

Alice and Bob are going to play a game on the strip. They take turns to make move. In one move the player must paint one of the remaining blank grids black, while keeping the rule that no two black grids are adjacent.

The game ends when one of the players is unable to paint any grid, and the score of the game is defined as the total number of grids painted black. Alice wants to minimize the score, while Bob wants to maximize it.

Given $n$ and the side starting the game, find out the final score when both players play optimally.
 

Input
The first line contains an integer $T(1\leq T \leq 10^5)$ - the number of test cases.

The first line of each test case contains an integer $n(1 \leq n \leq 10^9)$ and a string $s (s \in \{\texttt{Alice},\texttt{Bob}\})$ - the number of grids and the starting player of this game.
 

Output
For each test case, output the final score when both players play optimally in a single line.
 

Sample Input
4 3 Alice 3 Bob 19 Alice 23 Bob
 

Sample Output
1 2 8 10
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-22 03:43:30, Gzip enabled