# 2006百度之星程序设计大赛预赛题目之饭团的烦恼 参考解答

2350人阅读 评论(1)

#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include "math.h"

using namespace std;

struct food
{
string name;
int price;
bool isHun;
bool isXinla;
};

static int nFoodNeed; //饭团需要点的菜的数目
static int nPeople; //就餐的人数

//荤菜，素菜，辛辣，清淡菜
static int nHunFood;
static int nSuFood;
static int nXinFood;
static int nQindanFood;

{   //所选菜与15元相差多少
// test price
int totalPrice = 0;
{
totalPrice += (*iter).price;
}
return abs(totalPrice/nPeople - 15); //8折
}

{
double priceDistance = 1e+308;
double thisDistance = 0.0;
{
thisDistance = Distance15yuan(*iter);
if(thisDistance < priceDistance)
{
priceDistance = thisDistance;
}
}
}

bool TestCondition(vector<food> chosenFood)
{   //是否符合荤菜，素菜，辛辣，清淡菜数量要求
int nTestHunFood = 0;
int nTestSuFood = 0;
int nTestXinFood = 0;
int nTestQindanFood = 0;
for(vector<food>::iterator iter = chosenFood.begin(); iter != chosenFood.end(); ++iter)
{
if((*iter).isHun == true)
{
++nTestHunFood;
}
else
{
++nTestSuFood;
}
}
if(nTestHunFood != nHunFood)
{
return false;
}
if(nTestSuFood != nSuFood)
{
return false;
}

for(vector<food>::iterator iter = chosenFood.begin(); iter != chosenFood.end(); ++iter)
{

if((*iter).isXinla == true)
{
++nTestXinFood;
}
else
{
++nTestQindanFood;
}
}
if(nTestXinFood != nXinFood)
{
return false;
}
if(nTestQindanFood != nQindanFood)
{
return false;
}

return true;
}

{
if(leftFood.size() == nFoodNeed)
{
if(TestCondition(leftFood) == true)
{
}
return;
}

for(vector<food>::iterator iter = rightFood.begin(); iter != rightFood.end(); ++iter)
{
vector<food> newLeftFood(leftFood);
newLeftFood.push_back(*iter);
vector<food> newRightFood;

for(vector<food>::iterator i = iter+1; i != rightFood.end(); ++i)
{
newRightFood.push_back(*i);
}

}
}

void TryToSolove()
{
vector<food> left;
}

int main(int argc, char* argv[])
{
ifstream is(argv[1], ios::in | ios::binary);

is >> nFoodNeed;
is >> nPeople;
food temp;

for(int i = 0; i < nFoodMenu; ++i)
{
is >> temp.name;
is >> temp.price;
is >> temp.isHun ;
is >> temp.isXinla;
}
is >> nHunFood;
is >> nSuFood;
is >> nXinFood;
is >> nQindanFood;
TryToSolove();
double averagePrice = 0.0;
{
cout << (*iter).name << endl;
averagePrice += (*iter).price;
}

printf("%0.2f/n", averagePrice/nPeople*0.8);

return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：95306次
• 积分：1238
• 等级：
• 排名：千里之外
• 原创：23篇
• 转载：3篇
• 译文：0篇
• 评论：59条
文章分类
阅读排行
最新评论
交通查询
我的讨论
友情链接