CF初体验——Round #348, A

A题:(水题)
A. Little Artem and Presents
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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,1,2……这样排列下去,以3为一份,就这样分下去。

#include<iostream>
using namespace std;
int main(){
int num;
cin>>num;
int rest=num%3;
int group=num/3;
int ans=group*2;
if(rest!=0)ans++;
cout<<ans<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值