题目描述
因疫情原因,同学们只能在学校食堂就餐,学校为了保证同学们的就餐,准备了各种食品供大家选择。在学校餐厅,有 a 种汤,b 种饭,c 种面条,d 种荤菜,e 种素菜。为了保证膳食搭配,小王每顿饭都会点 1~2 样荤菜,1~2 样素菜(不重复)。同时,在小王心情好的时候,会点一样饭,再配上一种汤。在心情不好的时候,就只吃一种面条。因为经济有限,小王每次点餐的总价在 min~max 之间。小王想知道,总共有多少种不同的点餐方案。
输入描述
输入数据第一行包含一个整数 T,表示测试数据的组数,对于每组测试数据: 第一行为整数 a,b,c,d,e (0<a,b,c,d,e<=10) 第二行为 a 个大于零的整数,表示 a 种汤的价格 第三行为 b 个大于零的整数,表示 b 种饭的价格 第四行为 c 个大于零的整数,表示 c 种面条的价格 第五行为 d 个大于零的整数,表示 d 种荤菜的价格 第六行为 e 个大于零的整数,表示 e 种素菜的价格 第七行为两个整数 min max, 表示每次点餐的价格范围
输出描述
对于每组测试数据,输出一行,包含一个整数,表示点餐方案数。
样例输入
Copy to Clipboard
1 2 2 2 2 2 2 3 3 1 5 2 1 4 3 6 5 8
样例输出
Copy to Clipboard
3
代码如下
#include<bits/stdc++.h>
using namespace std;
/*
因疫情原因,同学们只能在学校食堂就餐,学校为了保证同学们的就餐,
准备了各种食品供大家选择。在学校餐厅,有 a 种汤,b 种饭,c 种面条,d 种荤菜,e 种素菜。
为了保证膳食搭配,小王每顿饭都会点 1~2 样荤菜,1~2 样素菜(不重复)。
同时,在小王心情好的时候,会点一样饭,再配上一种汤。在心情不好的时候,就只吃一种面条。
因为经济有限,
小王每次点餐的总价在 min~max 之间。小王想知道,总共有多少种不同的点餐方案。
*/
/*
1
2 2 2 2 2
2 3
3 1
5 2
1 4
3 6
5 8
*/
int n;
int main()
{
while (cin >> n)
{
for (int k = 0; k < n; k++)
{
/*初始化开始*/
int soup;
int rice;
int noodle;
int meat;
int vegetable;
cin >> soup >> rice >> noodle >> meat >> vegetable;
vector<int> soupPrice(soup, 0);
vector<int> ricePrice(rice, 0);
vector<int> noodlePrice(noodle, 0);
vector<int> meatPrice(meat, 0);
vector<int> vegetablePrice(vegetable, 0);
for (int i = 0; i < soup; i++)
cin >> soupPrice[i];
for (int i = 0; i < rice; i++)
cin >> ricePrice[i];
for (int i = 0; i < noodle; i++)
cin >> noodlePrice[i];
for (int i = 0; i < meat; i++)
cin >> meatPrice[i];
for (int i = 0; i < vegetable; i++)
cin >> vegetablePrice[i];
int min, max;
cin >> min >> max;
/*初始化 ----end */
int TypeNum = 0;
/*通过两个for循环,实现选择一种或两种菜*/
for (int meat1 = 0; meat1 < meat; meat1++)
{
for (int meat2 = meat1; meat2 < meat; meat2++)
{
int sumMeat = 0;
if (meat1 == meat2)
{
sumMeat = meatPrice[meat1];
}
else {
sumMeat = meatPrice[meat2] + meatPrice[meat1];
}
for (int vegetable1 = 0; vegetable1 < vegetable; vegetable1++)
{
for (int vegetable2 = vegetable1; vegetable2 < vegetable; vegetable2++)
{
int sumVegetable = 0;
if (vegetable1 == vegetable2)
{
sumVegetable = vegetablePrice[vegetable1];
}
else {
sumVegetable = vegetablePrice[vegetable1] + vegetablePrice[vegetable2];
}
// 通过四个循环把两个菜选完了
// 现在来选一下面条或者 米饭加汤
//1.心情好 米饭加汤
for (int rice1 = 0; rice1 < rice; rice1++)
{
for (int soup1 = 0; soup1 < soup; soup1++)
{
int sumRS = 0;
sumRS = ricePrice[rice1] + soupPrice[soup1];
int AllSum = sumRS + sumMeat + sumVegetable;
if (min <= AllSum && AllSum <= max)
{
TypeNum++;
}
}
}
//2.心情不好 只吃面条
for (int noodle1 = 0; noodle1 < noodle; noodle1++)
{
int sumNoodle = 0;
sumNoodle = noodlePrice[noodle1];
int AllSum = sumNoodle + sumMeat + sumVegetable;
if (min <= AllSum && AllSum <= max)
{
TypeNum++;
}
}
}
}
}
}
cout << TypeNum << endl;
}
}
return 0;
}