从现在开始,拟定属于你自己的健康饮食方案吧! 一份全新的健康饮食计划,将会使
你浑身充满活力。如果长时间坚持这样的饮食,那么不仅你患疾病的几率降低,而且还会比
预期寿命延长15 年。当然,随之而来的,还有你一直向往的好身材。假设供选择的菜单如
下:每份热量单位:大卡/100 克
假设供选择的菜单如下:每份热量单位:大卡/100 克
Boiled Fish with Pickled Cabbage and Chili 92
Sauted Sliced Pork with Pepper and Chili , Sichuan Style 231
Cold Noodles Sichuan Style 260
Fish Filets in Hot Chili Oil 239
Steamed Rice Rolls 196
Kung Pao Chicken 313
Hot and Sour Rice Noodles 144
Soybean Milk 92
Steamed Rice 31
Scrambled Egg with Scallion 81
Steamed Jiaozi 119
Sauted Sliced Pork with Black Fungus 143
Scrambled Egg with Leek 128
Steamed Bun Stuffed with Red Bean Paste 128
Yu-Shiang Shredded Pork (Sauted with Spicy Garlic Sauce) 134
输入最大摄入热量值(要求:每份菜只能要一份)
输出满足总摄入热量小于等于最大摄入热量值的菜品种类最多的组合
1
|
150
|
1
2
|
Steamed Rice 31
Scrambled Egg with Scallion 81
以后处理这种题的时候不要看数据数据麻烦,要用数组存储,如果用if语句就太麻烦了。
#include<stdio.h>
#include<string.h> #include<algorithm> using namespace std; struct date { char name[200]; int col; }; bool cmp(date a,date b) { if(a.col!=b.col) return a.col<b.col; else return strcmp(a.name,b.name)<0; } int main() { struct date arr[15]={{"Boiled Fish with Pickled Cabbage and Chili",92}, {"Sauted Sliced Pork with Pepper and Chili , Sichuan Style",231}, {"Cold Noodles Sichuan Style",260},{"Fish Filets in Hot Chili Oil",239},{"Steamed Rice Rolls",196}, {"Kung Pao Chicken",313},{"Hot and Sour Rice Noodles",144},{"Soybean Milk",92},{"Steamed Rice",31}, {"Scrambled Egg with Scallion",81},{"Steamed Jiaozi",119},{"Sauted Sliced Pork with Black Fungus",143}, {"Scrambled Egg with Leek",128},{"Steamed Bun Stuffed with Red Bean Paste",128}, {"Yu-Shiang Shredded Pork (Sauted with Spicy Garlic Sauce)",134}}; sort(arr,arr+15,cmp); int total; while(scanf("%d",&total)!=EOF) { int i,j,sum=0; for(i=0;i<15;i++) { sum=sum+arr[i].col; if(sum>total) break; } for(j=0;j<i;j++) printf("%s %d\n",arr[j].name,arr[j].col); } return 0; } |