@xunuo
2017-01-21T13:38:33.000000Z
字数 1724
阅读 1525
time limit per test1 second memory limit per test256 megabytes
贪心
来源:
codeforces 322 B Ciel and Flowers
vjudge C Ciel and Flowers
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 "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.
The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
input
3 6 9
output
6
input
4 4 4
output
4
input
0 0 0
output
0
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哦~
完整代码:
#include<stdio.h>#include<string.h>#include<math.h>#include<vector>#include<algorithm>using namespace std;int main(){int a,b,c;while(scanf("%d%d%d",&a,&b,&c)!=EOF){int a1=a%3;int b1=b%3;int c1=c%3;int m1=min(a1,min(b1,c1));int num1=a1-m1+b1-m1+c1-m1;///-----------------------///int m2=min(a,min(b,c));int a2=a-m2;int b2=b-m2;int c2=c-m2;int a3=a2%3;int b3=b2%3;int c3=c2%3;int num2=a3+b3+c3;///-----------------------///int ans;if(num1>num2){ans=a2/3+b2/3+c2/3+m2;if(m2!=0&&((a3==0&&b3==2&&c3==2)||(a3==2&&b3==0&c3==2)||(a3==2&&b3==2&c3==0)))ans+=1;}else{ans=a/3+b/3+c/3+m1;if((m2!=0)&&((a1==0&&b1==2&&c1==2)||(a1==2&&b1==0&&c1==2)||(a1==2&&b1==2&&c1==0)))ans+=1;}printf("%d\n",ans);}return 0;}
