需要7m,11m,17m的管子各10根,至少需要多少根100m的管子,并求出每根管子的利用率 如题:java编码实现! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.math.BigDecimal;import java.util.ArrayList;import java.util.List;/** * Created by IntelliJ IDEA. * User: rollet * Date: 13-1-25 * Time: 下午7:12 * 需要7m,11m,17m的管子各10根,至少需要多少根100m的管子,并求出每根管子的利用率 */public class TestTwo { public static void main(String[] args) { PIPE test = new PIPE(7, 11, 17, 10, 0, 0, 0, 0); List<PIPE> list = test.jisuan(100); for (PIPE pipe : list) { System.out.print(pipe.getA() + "=" + pipe.getAvalue() + ","); System.out.print(pipe.getB() + "=" + pipe.getBvalue() + ","); System.out.print(pipe.getC() + "=" + pipe.getCvalue() + ","); System.out.println("第" + pipe.getNumvalue() + "根管子使用率为" + new BigDecimal(pipe.getA() * pipe.getAvalue() + pipe.getB() * pipe.getBvalue() + pipe.getC() * pipe.getCvalue()).setScale(0) + "%"); } } static class PIPE { int a; int b; int c; int num; int avalue; int bvalue; int cvalue; int numvalue; PIPE(int a, int b, int c, int num, int avalue, int bvalue, int cvalue, int numvalue) { this.a = a; this.b = b; this.c = c; this.num = num; this.avalue = avalue; this.bvalue = bvalue; this.cvalue = cvalue; this.numvalue = numvalue; } public int getA() { return a; } public int getB() { return b; } public int getC() { return c; } public int getNum() { return num; } public int getAvalue() { return avalue; } public int getBvalue() { return bvalue; } public int getCvalue() { return cvalue; } public int getNumvalue() { return numvalue; } public List<PIPE> jisuan(int i) { List<PIPE> list = new ArrayList<PIPE>(); int ge = i; numvalue++; int alock = 0; int block = 0; int clock = 0; while (ge >= 0) { if (ge >= c && alock < num) { ge -= c; cvalue++; alock++; } else if (ge >= b && block < num) { ge -= b; bvalue++; block++; } else if (ge >= a && clock < num) { ge -= a; avalue++; clock++; } else { ge = i; list.add(new PIPE(a, b, c, num, avalue, bvalue, cvalue, numvalue)); numvalue++; avalue = 0; bvalue = 0; cvalue = 0; } if (clock == 10 && alock == 10 && block == 10) { list.add(new PIPE(a, b, c, num, avalue, bvalue, cvalue, numvalue)); break; } } return list; } }} for(int i=100/17;i>0;i--){ for(int j=(100-i*17)/11;j>0;j--){ if((100-i*17-j*11)%SEVEN==0){ System.out.println("17厘米的用了="+i); System.out.println("11厘米的用了="+j); System.out.println("7厘米的用了="+(100-i*17-j*11)/7); return ; } } }不知道是不是你想要的。 递归用法求帮助 关于java中的打包命令Main-Class和Class-path的用法 EJB3.0实体 持久化 急...我的帮助文档不能打开. 十万火急!!!大家帮帮我吧!!! 求最好的加密class文件的工具及下载地址 新手求助!运行不出来,看看是不是CLASSPATH的问题?? 求一个装箱问题的算法,学校竟然留这种作业…… 小问题,白拿分 !!!!请看这段代码!!!! Java类 成员函数和成员数据是私有的还是公有的? text 读写问题 急
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;/**
* Created by IntelliJ IDEA.
* User: rollet
* Date: 13-1-25
* Time: 下午7:12
* 需要7m,11m,17m的管子各10根,至少需要多少根100m的管子,并求出每根管子的利用率
*/
public class TestTwo {
public static void main(String[] args) {
PIPE test = new PIPE(7, 11, 17, 10, 0, 0, 0, 0);
List<PIPE> list = test.jisuan(100);
for (PIPE pipe : list) {
System.out.print(pipe.getA() + "=" + pipe.getAvalue() + ",");
System.out.print(pipe.getB() + "=" + pipe.getBvalue() + ",");
System.out.print(pipe.getC() + "=" + pipe.getCvalue() + ",");
System.out.println("第" + pipe.getNumvalue() + "根管子使用率为" + new BigDecimal(pipe.getA() * pipe.getAvalue() + pipe.getB() * pipe.getBvalue() + pipe.getC() * pipe.getCvalue()).setScale(0) + "%");
}
} static class PIPE {
int a;
int b;
int c;
int num;
int avalue;
int bvalue;
int cvalue;
int numvalue;
PIPE(int a, int b, int c, int num, int avalue, int bvalue, int cvalue, int numvalue) {
this.a = a;
this.b = b;
this.c = c;
this.num = num;
this.avalue = avalue;
this.bvalue = bvalue;
this.cvalue = cvalue;
this.numvalue = numvalue;
} public int getA() {
return a;
} public int getB() {
return b;
} public int getC() {
return c;
} public int getNum() {
return num;
} public int getAvalue() {
return avalue;
} public int getBvalue() {
return bvalue;
} public int getCvalue() {
return cvalue;
}
public int getNumvalue() {
return numvalue;
} public List<PIPE> jisuan(int i) {
List<PIPE> list = new ArrayList<PIPE>();
int ge = i;
numvalue++;
int alock = 0;
int block = 0;
int clock = 0;
while (ge >= 0) {
if (ge >= c && alock < num) {
ge -= c;
cvalue++;
alock++;
} else if (ge >= b && block < num) {
ge -= b;
bvalue++;
block++;
} else if (ge >= a && clock < num) {
ge -= a;
avalue++;
clock++;
} else {
ge = i;
list.add(new PIPE(a, b, c, num, avalue, bvalue, cvalue, numvalue));
numvalue++;
avalue = 0;
bvalue = 0;
cvalue = 0;
}
if (clock == 10 && alock == 10 && block == 10) {
list.add(new PIPE(a, b, c, num, avalue, bvalue, cvalue, numvalue));
break;
}
}
return list;
}
}}
for(int j=(100-i*17)/11;j>0;j--){
if((100-i*17-j*11)%SEVEN==0){
System.out.println("17厘米的用了="+i);
System.out.println("11厘米的用了="+j);
System.out.println("7厘米的用了="+(100-i*17-j*11)/7);
return ;
}
}
}不知道是不是你想要的。