CodeForces 669ALittle Artem and Presents

Description

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.

Sample Input

Input
1
Output
1
Input
2
Output
1
Input
3
Output
2
Input
4
Output
3

Source

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)

代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
int main()
{
 	int n;
	 while(scanf("%d",&n)!=EOF)
	 {
	 	int k=0,sum=0;
	 		while(n>0)
	 		{
	 			if(n==1||n==2)
	 			{
	 				sum++;
	 				printf("%d\n",sum);
	 				break;
				 }
	 			if(k%2==0)
	 			{
	 				n--;
	 				sum++;
	 				k++;
				 }
				 else
				 {
				 	n=n-2;
				 	sum++;
				 	k++;
				 }
			 }
		 } 
	return  0;
}
题意:女神喜欢石头(哪有女神会喜欢石头啊?),所以屌丝满心欢喜的给女神送石头,但是女神不喜欢被连续送同样数目的石头。你知道屌丝一共有多少块石头,所以屌丝求助你他最多能送多少次。

思路:要送最多次,而且相同两次不一样,那一次就送一块或者两块。这样判断,可以设一个数k,每次送的时候都k++;偶数k送一块,单数k送两块。到最后如果剩下一块或者两块的时候,只能送一次了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值