Codeforces Round #622 (Div. 2) A. Fast Food Restaurant

Tired of boring office work, Denis decided to open a fast food restaurant.

On the first day he made aa portions of dumplings, bb portions of cranberry juice and cc pancakes with condensed milk.

The peculiarity of Denis's restaurant is the procedure of ordering food. For each visitor Denis himself chooses a set of dishes that this visitor will receive. When doing so, Denis is guided by the following rules:

  • every visitor should receive at least one dish (dumplings, cranberry juice, pancakes with condensed milk are all considered to be dishes);
  • each visitor should receive no more than one portion of dumplings, no more than one portion of cranberry juice and no more than one pancake with condensed milk;
  • all visitors should receive different sets of dishes.

What is the maximum number of visitors Denis can feed?

Input

The first line contains an integer tt (1t5001≤t≤500) — the number of test cases to solve.

Each of the remaining tt lines contains integers aa, bb and cc (0a,b,c100≤a,b,c≤10) — the number of portions of dumplings, the number of portions of cranberry juice and the number of condensed milk pancakes Denis made.

Output

For each test case print a single integer — the maximum number of visitors Denis can feed.

Example
Input
 
7
1 2 1
0 0 0
9 1 7
2 2 3
2 3 2
3 2 2
4 4 4
Output
 
3
0
4
5
5
5
7
思维题,需要贪心一下。可以想到最多只有其中配餐情况。先把输入的三个数sort一下。先考虑只发一种的情况,分别判断三个数是否大于0,是的话ans++,原数--。然后判断两种的情况,这里要注意,要贪心地优先拿数量最多的菜和较少的两种搭配(顺序无所谓) 可以考虑一个样例的2 2 3.然后三种菜全选的话直接判断能不能满足就行。
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a[3];
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        int cnt=0;
        if(a[0])cnt++,a[0]--;
        if(a[1])cnt++,a[1]--;
        if(a[2])cnt++,a[2]--;
        if(a[0]>0&&a[2]>0)cnt++,a[0]--,a[2]--;//贪心分配 
        if(a[1]>0&&a[2]>0)cnt++,a[1]--,a[2]--;
        if(a[0]>0&&a[1]>0)cnt++,a[0]--,a[1]--;
        if(a[0]>0&&a[1]>0&&a[2]>0)cnt++;
        cout<<cnt<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/lipoicyclic/p/12356846.html