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
1
1
2
1
3
2
4
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送两块。到最后如果剩下一块或者两块的时候,只能送一次了。