ÓÃcʵÏÖ±³°üÎÊÌ⣨̰ÐÄ£©
ºÃ¾ÃÒÔÇ°×öµÄÒ»¸ö³ÌÐò£¬Ì°ÐIJßÂÔʵÏÖ±³°üÎÊÌ⣬cʵÏÖ¡£
×ܽáÔÚÕâÀÒÔ±¸ÒÔºóºÍ±ðÈ˲éÕÒ¡£
//±³°üÎÊÌâ
#include "stdio.h"
#define MAX 10
void main()
{
int w[MAX]={0,10,130,15,60,25}; //´æ·ÅÖÊÁ¿
int v[MAX]={0,30,5,10,20,25}; //´æ·Å¼ÛÖµ
float a[MAX]={0}; //´æ·ÅÈ¡µÄÁ¿£¬¼´Êä³ö½á¹û¡£
int m,n,i,max;
m=100;n=5;
/*
scanf("%d %d",&m,&n);
for(i=1;i<=n;i++)
scanf("%d",&w[i]); //ÖØÁ¿ºÍ¼ÛÖµ¶¼´Ó1ºÅ¿ªÊ¼´æ£¬ÁãºÅ£¨=0£©¿ÕÏ£¬Ò»»á×ömax
for(i=1;i<=n;i++)
scanf("%d",&v[i]);*/
for(i=1;i<=n;i++)
printf("%d: %d ",w[i],v[i]);
do{
max=0;
for(i=1;i<=n;i++)
if(v[i]>v[max])
{
max=i;
}
v[max]=0;
if(m>=w[max]) //Èç¹û¹»·Å¡£
{
m-=w[max];
a[max]=1;
}
else
{
//ÕâÑùµÃµ½Ò»¸ö¸ºÖµ£¬¾Í»ádo whileÌø³öÑ»·¡£
a[max]=((float)m)/w[max];
m-=w[max];
}
}while(m>0);
printf("\nThe result is:\n");
for(i=1;i<=n;i++)
printf("%f ",a[i]);
}
Ïà¹ØÎĵµ£º
±¾ÎÄÌÖÂÛÁËC³ÌÐòµÄÍⲿ±äÁ¿ºÍº¯ÊýµÄһЩÐÔÖÊ£¬½áºÏʵ¼ÊµÄ±à³Ì£¬¸ø³öÁËʹÓÃÍⲿ±äÁ¿ºÍº¯ÊýµÄ·½·¨¡£
¹Ø¼ü×Ö£ºC³ÌÐò£¬Íⲿ±äÁ¿£¬º¯Êý
¡¡¡¡C³ÌÐòÓÉÒ»×é¶ÔÏó×é³É£¬ÕâЩ¶ÔÏó°üÀ¨³ÌÐòÖÐËùʹÓõıäÁ¿ºÍʵÏÖÌض¨¹¦Äܵĺ¯Êý¡£±äÁ¿¿ÉÒÔ·ÖΪº¯ÊýÄÚ²¿¶¨Ò塢ʹÓõıäÁ¿ºÍº¯ÊýÍⲿ¶¨ÒåµÄ±äÁ¿£¬Í¨³£Çé¿öÏ£¬°Ñº¯ÊýÄÚ²¿¶¨Ò塢ʹÓõıäÁ¿³ÆÎ ......
/*
**ÅжÏC?ÐÐ??¾³µÄ³ÌÐò
*/
/*
**¾²?³õʼ»¯
*/
int static_variable=5;
void
f()
{
register int i1, i2, i3, i4, i5, i6, i7, i8, i9, i10;
register char *c1, *c2, *c3, *c4, *c5, *c6, *c7 , *c8, *c9, *c10;
extern int a_very_long_name_to_sec_how_long_they_can_be;
double ......
CAPTION: ¹ØÓÚC/C++ÖÐÄÚ´æ¿Õ¼äµÄ»®·Ö
AUTHOR: aIsland Õª×ÔÖйúITʵÑéÊÒ
DATE: 2010-05-30
E-MAIL: aIsland@live.cn
QQ: 418662213
P.S.
1.Bolanlan|ËæÐÄhigh|aIsland Èý¸öÍøÃû¾ùΪ±¾ÈË
2.ÉùÃ÷aIsland ËùÊÕ¼µÄËùÓÐÎÄÕÂÆäÖø×÷Ȩ¶¼ÊôÓÚÔ´´×÷Õß
  ......
/*
* File: main.cpp
* Author: Vicky
*
* Created on 2010Äê5ÔÂ8ÈÕ, ÏÂÎç2:47
*/
#include <iostream>
using namespace std;
void swap(int x, int y) {
cout << "x and y swap before : " << x << "\t" << y << endl;
int i = x;
x = y;
y = i; ......