A. Arena of Greed

news/2025/3/15 13:42:50/

链接:https://codeforces.com/problemset/problem/1425/A

Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia.

The game is played by two people taking turns, where Mr. Chanek takes the first turn. Initially, there is a treasure chest containing NN gold coins. The game ends if there are no more gold coins in the chest. In each turn, the players can make one of the following moves:

  • Take one gold coin from the chest.
  • Take half of the gold coins on the chest. This move is only available if the number of coins in the chest is even.

Both players will try to maximize the number of coins they have. Mr. Chanek asks your help to find the maximum number of coins he can get at the end of the game if both he and the opponent plays optimally.

Input

The first line contains a single integer TT (1≤T≤105)(1≤T≤105) denotes the number of test cases.

The next TT lines each contain a single integer NN (1≤N≤1018)(1≤N≤1018).

Output

TT lines, each line is the answer requested by Mr. Chanek.

Example

input

Copy

2
5
6

output

Copy

2
4

Note

For the first case, the game is as follows:

  1. Mr. Chanek takes one coin.
  2. The opponent takes two coins.
  3. Mr. Chanek takes one coin.
  4. The opponent takes one coin.

For the second case, the game is as follows:

  1. Mr. Chanek takes three coins.
  2. The opponent takes one coin.
  3. Mr. Chanek takes one coin.
  4. The opponent takes one coin.

思路:贪就完事了,特别注意一下4的情况即可

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=4e5+7;
const int mod=1e9+7;
char x;
ll n,t,s;
int main()
{cin>>t;while(t--){cin>>n;s=0;int k=0;while(n){if(k%2==0){if(n%2==1){s++;n--;}else{if((n/2)%2==0&&n>4){s++;n--;}else{s+=n/2;n/=2;}}}else{if(n%2==1)n--;else if((n/2)%2==0&&n>4){n--;}elsen/=2;}k++;}cout<<s<<endl;}return 0;
}

 


http://www.ppmy.cn/news/627141.html

相关文章

Archer

CF上的一道题&#xff0c;就是求赢的概率。 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<iomanip> #include<algorithm> #include<cctype> #include<stack> #include<queue> #inc…

blade

Laravel 框架中的 Blade 模板引擎&#xff0c;很好用&#xff0c;但是在官方文档中有关 Blade 的介绍并不详细&#xff0c;有些东西没有写出来&#xff0c;而有些则是没有说清楚。比如&#xff0c;使用中可能会遇到这样的问题&#xff1a; 1.yield 和 section 都可以预定义可替…

Laravel Blade

Laravel默认使用Blade作为模板引擎&#xff0c;Blade中可使用原生PHP代码输出。Blade模板使用.blade.php作为文件扩展名。Blade模板最终都将被“编译”(正则替换)成原生PHP代码并缓存&#xff0c;除非模板文件被修改否则不会重新编译。 模板引擎需要完成最基本三项功能&#xf…

ARCH++

ARCH: Animation-Ready Clothed Human Reconstruction Revisited 可直接用于动画的穿衣服人体重建 我们提出了一种基于图像的三维化身重建方法ARCH&#xff0c;该方法可以重建具有任意服装风格的3D化身。我们重建的化身是动画就绪和高度逼真的&#xff0c;在输入视图的可见区…

Blazor 简介

Blazor 是一个用于使用 .NET 生成交互式客户端 Web UI 的框架&#xff1a; 使用 C# 代替 JavaScript 来创建丰富的交互式 UI。共享使用 .NET 编写的服务器端和客户端应用逻辑。将 UI 呈现为 HTML 和 CSS&#xff0c;以支持众多浏览器&#xff0c;其中包括移动浏览器。 使用 .…

chaosblade使用(二十四):blade create jvm

1 介绍 jvm 本身相关场景&#xff0c;以及可以指定类&#xff0c;方法注入延迟、返回值、异常故障场景&#xff0c;也可以编写 groovy 和 java 脚本来实现复杂的场景。目前支持的场景如下 [blade create jvm CodeCacheFilling](blade create jvm CodeCacheFilling.md) 填充 j…

Blazor 开发

1.跳转页面 在视图razor页面头部增加 inject NavigationManager NavigationManager 在OnInitializedAsync()内增加 NavigationManager.NavigateTo("http://baidu.com"); 2.表字段内部增加控件 <TableColumn bind-Field"context.complete_degree"&…

Armitage

一&#xff0c;目录 关于Armitage在我们开始之前...入门如何让任何女人与您交谈用户界面之旅这么多漂亮的屏幕截图主机管理您必须找到它们来破解它们。剥削这是有趣的东西剥削后&#xff0c;这是非常有趣的东西机动性遍及网络并达到更多目标团队Metasploit这是网络攻击管理&am…