• Educational Codeforces Round 133 (Rated for Div. 2) A. 2-3 Moves


    Problem - A - Codeforces

    You are standing at the point 00 on a coordinate line. Your goal is to reach the point nn. In one minute, you can move by 22 or by 33 to the left or to the right (i. e., if your current coordinate is xx, it can become x−3x−3, x−2x−2, x+2x+2 or x+3x+3). Note that the new coordinate can become negative.

    Your task is to find the minimum number of minutes required to get from the point 00 to the point nn.

    You have to answer tt independent test cases.

    Input

    The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt lines describing the test cases follow.

    The ii-th of these lines contains one integer nn (1≤n≤1091≤n≤109) — the goal of the ii-th test case.

    Output

    For each test case, print one integer — the minimum number of minutes required to get from the point 00 to the point nn for the corresponding test case.


    你站在坐标线上的 0 点。 你的目标是到达点 n。 在一分钟内,您可以向左或向右移动 2 或 3(即,如果您当前的坐标是 x,它可以变为 x−3、x−2、x+2 或 x+3 )。 请注意,新坐标可能变为负数。

    你的任务是找出从点 0 到点 n 所需的最少分钟数。

    你必须回答 t 个独立的测试用例。

    输入
    输入的第一行包含一个整数 t (1≤t≤104) — 测试用例的数量。 然后是描述测试用例的 t 行。

    这些行的第 i 行包含一个整数 n (1≤n≤109)——第 i 个测试用例的目标。

    输出
    对于每个测试用例,打印一个整数——对应测试用例从点 0 到点 n 所需的最小分钟数。

    例子
    输入复制
    4
    1
    3
    4
    12
    输出复制
    2
    1
    2
    4

    1. #include
    2. using namespace std;
    3. typedef long long ll ;
    4. int t;
    5. ll n;
    6. int main()
    7. {
    8. cin>>t;
    9. while(t--)
    10. {
    11. cin>>n;
    12. ll bns=0;
    13. if(n==1)cout<<2<
    14. else
    15. {
    16. if(n%3==0&&n%2==0)
    17. {
    18. bns=n/3;
    19. }
    20. else if(n%2==0&&n%3!=0)
    21. {
    22. bns=n/2;
    23. }
    24. else if(n%3==0&&n%2!=0)
    25. {
    26. bns=n/3;
    27. }
    28. ll ans=((n-2)/3);
    29. ans+=1;
    30. if((n-2)%3==2)
    31. {
    32. ans+=1;
    33. }
    34. if((n-2)%3==1)
    35. {
    36. ans+=2;
    37. }
    38. ll cns=(n-3)/2;
    39. cns+=1;
    40. if((n-3)%2)
    41. {
    42. cns+=2;
    43. }
    44. if(bns!=0)
    45. cout<<min(min(cns,ans),bns)<
    46. else
    47. cout<<min(cns,ans)<
    48. }
    49. }
    50. }

  • 相关阅读:
    数据通信网络之IPv6以太网多层交换
    文档管理软件将办公室的业务模式转变为无纸化远程业务模式,提高员工生产力和保留率
    进程之间是怎么协作的(硬件实现方法)
    从无到有跑通KAPAO
    Ubuntu Linux 23.10安装manimgl
    ASP.NET Core 分层服务注入思想实现
    【设计模式】策略模式
    GemBox.Bundle 47.0.1315 最新Crack
    前后缀分解
    肾囊肿会出现什么异常?
  • 原文地址:https://blog.csdn.net/qq_62079079/article/details/126172750