CodeForces 669A Little Artem and Presents
2016-06-07 12:52
267 查看
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
output
input
output
input
output
input
output
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
cc14sample, 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.
思路:因为他要得到最大的给礼物次数,所以只需按照 1 2 1 2 1 2 ......的给就行了
AC代码;
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int s=0;
if(n<3)
s=1;
else if(n%3==0)
s=n/3*2;
else
s=n/3*2+1;
printf("%d\n",s);
}
return 0;
}
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
cc14sample, 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.
思路:因为他要得到最大的给礼物次数,所以只需按照 1 2 1 2 1 2 ......的给就行了
AC代码;
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int s=0;
if(n<3)
s=1;
else if(n%3==0)
s=n/3*2;
else
s=n/3*2+1;
printf("%d\n",s);
}
return 0;
}
相关文章推荐
- R语言实战:机器学习与数据分析源代码1
- Cookie和Session的区别详解
- 贝叶斯推断
- Android自定义View实现可以拖拽的GridView
- javascript 输出 素数/质数
- SQl之PreparedStatement用法---------( 一 )
- 用HTML5的canvas实现抽奖刮刮卡的效果(只需十几行代码)
- C++中利用系统函数启动或关闭外部程序(待完善)
- linux基本命令(61)——wget命令
- # Swust 12th acm 邀请赛# [ E ] 01 String [题解]
- SQL中Group By的使用
- Qt msvc版安装使用部署发布
- 再说Java动态代理
- spring+jedis配置问题
- Java线程之线程协作(生产者/消费者问题)
- 断点续传 scp rsync
- 截取本地URL请求(NSURLProtocol)
- 谷歌开发者周刊 第26期
- [已]The specified child already has a parent. You must call removeView() on the child's parent first.
- Spring基础学习(五)—事务管理