软考程序员:贪心算法在背包中的应用[6]

程序员 责任编辑:SJMORS 2011-01-17

添加老师微信

备考咨询

加我微信

摘要:{if((temp<tempArray[j])&&(sortResult[j]==0)){temp=tempArray[j];index=j;}}//对w[i]作标记排序if(sortResult[index]==0){sortResult[index]=++k;}}//修改效益最低的sortResult[i]标记for(i=0;i<n;i++){if(sortResult[i]==0){sortResult[i]=++k;}}return

  {
  if ((temp < tempArray[j]) && (sortResult[j] == 0))
  {
  temp = tempArray[j];
  index = j;
  }
  }
  //对w[i]作标记排序
  if (sortResult[index] == 0)
  {
  sortResult[index] = ++k;
  }
  }
  //修改效益最低的sortResult[i]标记
  for (i = 0; i < n; i++)
  {
  if (sortResult[i] == 0)
  {
  sortResult[i] = ++k;
  }
  }
  return;
  }
  //得到本算法的所有输入信息
  void getData(float p[], float w[], int *n)
  {
  int i = 0;
  printf(“please input the total count of object: ”);
  scanf(“%d”, n);
  printf(“Please input array of p :\n”);
  for (i = 0; i < (*n); i++)
  {
  scanf(“%f”, &p[i]);
  }
  printf(“Now please input array of w :\n”);

[1]  [2]  [3]  [4]  [5]  [6]  [7]  

更多资料
更多课程
更多真题
温馨提示:因考试政策、内容不断变化与调整,本网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准!

软考备考资料免费领取

去领取