当前位置:网站首页>Edu Codeforces Round 133 A. 2-3 Moves
Edu Codeforces Round 133 A. 2-3 Moves
2022-08-08 00:50:00 【Curz酥】
题目链接:https://codeforces.com/contest/1716/problem/A
思路:如果目标是1,那么一定是走2步。其他状况一定走n/3(答案向上取整)步,因为给定一个目标n(n≠1),至少需要走(n/3)步才能到达或到达大于n的地方,答案不会比这个还小了。然后枚举一些答案找规律,可以发现如果不能正好到达n,那么需要的步数一定是(n/3)+1步。
C++代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int t, n;
cin >> t;
while(t--){
cin >> n;
if(n == 1) cout << "2" << "\n";
else if(n % 3 == 0) cout << n / 3 << "\n"; //向上取整的步骤
else cout << n / 3 + 1 << "\n"; //向上取整的步骤
}
return 0;
}
边栏推荐
猜你喜欢

家乡的黄桃

Let’s talk about the anti-reverse circuit in combination with the actual situation (summary of the anti-reverse circuit)

kaggle小白必看:小白常见的2个错误解决方案

sci 顶刊中的 3D 密度函数图

继承关系下构造方法的访问特点

Flexible and easy-to-use sql monitoring script part6

Rdkit常用命令/参数设置

SAP 的MPN功能

【愚公系列】2022年08月 Go教学课程 032-结构体方法继承
![[LeetCode周赛复盘] 第 305 场周赛20220807](/img/9e/a09e0ebec985341f972ccc6b15aa53.png)
[LeetCode周赛复盘] 第 305 场周赛20220807
随机推荐
带你刷(牛客网)C语言百题(第五天)
pycharm connect to remote server
使用jmh框架进行benchmark测试
【自然语言】------朴素贝叶斯对新闻进行预测分类
[QNX Hypervisor 2.2 User Manual] 10.11 vdev progress
win10 rdkit下载及使用
RPA与传统编程谁才是王者
立秋是中稻收割的日子
空间地理数据可视化之 leaflet 包及其拓展
MD5加密工具类
High performance cloud storage MinIO combat - native data object
倒水问题(暑假每日一题 17)
redis分布式锁实现
陈强教授《机器学习及R应用》课程 第六章作业
leetcode-每日一题636. 函数的独占时间(模拟栈)
Embedded sharing collection 31-serial port
eyb:Redis的学习(1)
Modern enterprise architecture framework - business architecture
Stream did not contain valid UTF-8 ——vs code 中 rust在debug时报错,中文乱码问题
空间地理数据可视化之 tmap 包及其拓展