[2016-04-25][codeforces][669][A]Little Artem and Presents]
时间:2016-04-25 19:50:32 星期一
题目编号:[2016-04-25][codeforces][669][A]Little Artem and Presents]
题目大意:有n个礼物送给某人,每次送的礼物的数目不能和上次一样,问最多能送多少次
分析:
- 贪心,1,2,1,2交替送,剩下的不管是1个还是2个,最多只能送一次
- 答案:ans = n / 3 * 2 + (n % 3? 1 :0)
遇到的问题:
#include<cstdio>using namespace std;int main(){int n;scanf("%d",&n);int ans = n / 3 * 2 + (n%3?1:0);printf("%d\n",ans);return 0;}
浙公网安备 33010602011771号