[关闭]
@xunuo 2017-01-21T21:38:33.000000Z 字数 1724 阅读 1256

Ciel and Flowers-----(一个非常简单的贪心水题呀呀呀呀呀~~~)


time limit per test1 second memory limit per test256 megabytes

贪心

来源:
codeforces 322 B Ciel and Flowers
vjudge C Ciel and Flowers


Description

Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:

Input

The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 109) — the number of red, green and blue flowers.

Output

Print the maximal number of bouquets Fox Ciel can make.

Examples

input

3 6 9

output

6

input

4 4 4

output

4

input

0 0 0

output

0

Note

In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.

In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.

题意:

有红、绿、蓝三种颜色的花,
要组成一束红花需要三朵红花
要组成一束绿花需要三朵绿花
要组成一束蓝花需要三朵蓝花
要组成一束混合花需要1朵红花,1朵绿花,1朵蓝花;
给你三种花的数量,让你求出最多可以组成多少束花

解题思路:

这个题非常简单,对吧~~呵呵哒,然而你忽略了:若当剩下的花为红花0朵,绿花和蓝花都分别为2朵时, 时,你可以减少一束红花,而增加两束混合花~~是不是啊!!!
唉~~你好zz哦~

完整代码:

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<vector>
  5. #include<algorithm>
  6. using namespace std;
  7. int main()
  8. {
  9. int a,b,c;
  10. while(scanf("%d%d%d",&a,&b,&c)!=EOF)
  11. {
  12. int a1=a%3;
  13. int b1=b%3;
  14. int c1=c%3;
  15. int m1=min(a1,min(b1,c1));
  16. int num1=a1-m1+b1-m1+c1-m1;
  17. ///-----------------------///
  18. int m2=min(a,min(b,c));
  19. int a2=a-m2;
  20. int b2=b-m2;
  21. int c2=c-m2;
  22. int a3=a2%3;
  23. int b3=b2%3;
  24. int c3=c2%3;
  25. int num2=a3+b3+c3;
  26. ///-----------------------///
  27. int ans;
  28. if(num1>num2)
  29. {
  30. ans=a2/3+b2/3+c2/3+m2;
  31. if(m2!=0&&((a3==0&&b3==2&&c3==2)||(a3==2&&b3==0&c3==2)||(a3==2&&b3==2&c3==0)))
  32. ans+=1;
  33. }
  34. else
  35. {
  36. ans=a/3+b/3+c/3+m1;
  37. if((m2!=0)&&((a1==0&&b1==2&&c1==2)||(a1==2&&b1==0&&c1==2)||(a1==2&&b1==2&&c1==0)))
  38. ans+=1;
  39. }
  40. printf("%d\n",ans);
  41. }
  42. return 0;
  43. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注