| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4043 人关注过本帖
标题:[求助]一个关于牛奶的问题!外加BT作业!!!
只看楼主 加入收藏
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
假定价钱是从小到大已经排好序的.并且保存在w[]中.num[]对应存储数量(也可以定义结构体,把这两个包起来)
i=0;sum=0;
while(i<m)
{
if(num[i]<=n)
{
n-=num[i];
sum+=num[i]*w[i]
}
else
{
break;
}
i++;
}
if(n!=0)
{
sum+=w[i]*n;
}
printf("%d",sum);




倚天照海花无数,流水高山心自知。
2006-11-03 20:49
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
呵呵!这回正确了!
我还想请教一下怎样判断n个数的大小,让他们从小到大输出,n是未知的!
谢谢了!

该学习了。。。
2006-11-03 20:50
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
n不就是农民的个数吗

倚天照海花无数,流水高山心自知。
2006-11-03 20:52
我不是郭靖
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:494
专家分:6
注 册:2006-10-4
收藏
得分:0 

n怎么可能是未知的呢?你说个例子看看


2006-11-03 20:53
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
我不是专只这个题,是一般情况。

该学习了。。。
2006-11-03 20:54
我不是郭靖
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:494
专家分:6
注 册:2006-10-4
收藏
得分:0 
以下是引用zhanghuan_10在2006-11-3 20:54:49的发言:
我不是专只这个题,是一般情况。

你最好举个例子
既然叫你排序,数的个数就不可能不知道


2006-11-03 20:58
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
是啊!呵呵!n是已知的,我昨天问了同学,他说用泡沫排序法。

该学习了。。。
2006-11-04 08:17
leowsw
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-11-4
收藏
得分:0 
贪心
2006-11-05 02:16
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 

Goldbach's Conjecture
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:

Every even number greater than 4 can be written as the sum of two odd prime numbers.

For example:

8 = 3 + 5. Both 3 and 5 are odd prime numbers.
20 = 3 + 17 = 7 + 13.
42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.

Today it is still unproven whether the conjecture is right. (Oh wait, I have the proof of course, but it is too long to write it on the margin of this page.)

Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a million.

Input
The input will contain one or more test cases.

Each test case consists of one even integer n with 6 <= n < 1000000.

Input will be terminated by a value of 0 for n.

Output
For each test case, print one line of the form n = a + b, where a and b are odd primes. Numbers and operators should be separated by exactly one blank like in the sample output below. If there is more than one pair of odd primes adding up to n, choose the pair where the difference b - a is maximized. If there is no such pair, print a line saying "Goldbach's conjecture is wrong."

Sample Input
8
20
42
0

Sample Output
8 = 3 + 5
20 = 3 + 17
42 = 5 + 37


该学习了。。。
2006-11-05 14:20
yuchujin
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2006-7-25
收藏
得分:0 
为什么你的题目都是英文的啊

........晕 这个BBS不能贴图.......... G-G-G-G-G-G-G-UNIT
2006-11-05 17:31
快速回复:[求助]一个关于牛奶的问题!外加BT作业!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016428 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved