【Ciel and Flowers】【CodeForces - 322B】(思維)
阿新 • • 發佈:2018-11-28
題目:
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:
- To make a "red bouquet", it needs 3 red flowers.
- To make a "green bouquet", it needs 3 green flowers.
- To make a "blue bouquet", it needs 3 blue flowers.
- To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower.
Help Fox Ciel to find the maximal number of bouquets she can make.
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.
解題報告: 入眼你會發現是道比較水的題目,整體解法不多解釋,但是存在坑點,因為有一個情況就是6 8 8,最多應該是7朵花,6(3+1+1+1,3*2+1+1,3*2+1+1),,所以在整體的局勢下,需要增加一種判斷。
ac程式碼:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn=1e5+100;
int main()
{
int a,b,c,d,e,f;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
int ans=0;
ans=min(a,min(b,c));
if(ans==0)
{
cout<<a/3+b/3+c/3<<endl;
continue;
}
a-=ans;
b-=ans;
c-=ans;
ans+=a/3+b/3+c/3;
if(a%3+b%3+c%3==4)
ans++;//補貪心的不足
printf("%d\n",ans);
}
return 0;
}