zoukankan      html  css  js  c++  java
  • codeforces 669A A. Little Artem and Presents(水题)

    题目链接:

    A. Little Artem and Presents

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.

    How many times can Artem give presents to Masha?

    Input
     

    The only line of the input contains a single integer n (1 ≤ n ≤ 109) — number of stones Artem received on his birthday.

    Output
     

    Print the maximum possible number of times Artem can give presents to Masha.

    Examples
     
    input
    1
    output
    1
    input
    2
    output
    1
    input
    3
    output
    2
    input
    4
    output
    3
    Note

    In the first sample, Artem can only give 1 stone to Masha.

    In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.

    In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.

    In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.

    题意

    问每次给个数,相邻的数不能一样,和为n,怎么才能使次数最多,最多为多少次;

    思路

    次数最多,那么就尽量为1和2了;

    AC代码

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll mod=1e9+7;
    const ll inf=1e15;
    const int N=1e5+6;
    
    int main()
    {
    
        int n;
        scanf("%d",&n);
        if(n%3==0)printf("%d
    ",n/3*2);
        else if(n%3==1)printf("%d
    ",n/3*2+1);
        else
        {
            printf("%d
    ",n/3*2+1);
        }
        return 0;
    }
  • 相关阅读:
    PostgreSql开启远程连接
    Cannot resolve scoped service from root provider
    运行项目报错MSB 401 "RazorTagHelper" 任务意外失败
    win10远程共享文件夹
    Typora 快捷方式给字体设置颜色
    markdown编辑器typora支持图床的功能
    【HTML】二、HTML标签
    【HTML】一、初识HTML
    sublime text3安装后html:5+Tab不能快速生成html头部信息的解决办法
    markdown语法
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5430605.html
Copyright © 2011-2022 走看看