大家帮我找下规律,列个计算公式出来,谢谢!!!

xuliang021 2010-03-23 05:33:02
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
三组数每组选一个出来,
组成“0”的概率有几次 “1次” 0+0+0=0
组成“1”的概率有几次 “3次” 0+0+1=1,0+1+0=1,1+0+0=1
组成“2”的概率有几次 “6次” 0+0+2=2,0+2+0=2,2+0+0=2,1+1+0=2,1+0+1=2,0+1+1=2
…………
组成“27”的概率有几次 “1次” 9+9+9=27
...全文
169 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
whd3331933 2010-03-27
  • 打赏
  • 举报
回复
留个章 用来学习
sun1950 2010-03-24
  • 打赏
  • 举报
回复
可以算到14,另一般是一样的,效率稍微高点
skran 2010-03-24
  • 打赏
  • 举报
回复

import java.io.*;

public class Gailv {
public static void main(String[] args) {
int[] array1 = new int[10];
int[] array2 = new int[10];
int[] array3 = new int[10];
for(int i=0; i<10; i++) {
array1[i] = array2[i]= array3[i] = i;
}
System.out.println("请输入要组成的数:");
int number = 0;
boolean flag = true;
int count = 0;
while(flag) {
try{
InputStreamReader ins = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(ins);
number = Integer.parseInt(bf.readLine());
//System.out.println("您输入的数是" + number);

if (number >= 0 && number <= 27) {
for(int i=0; i<10&&array1[i]<=number; i++) {
for(int j=0; j<10&&array2[j]<=number; j++) {
for(int k=0; k<10&&array3[k]<=number; k++) {
if(array1[i]+array2[j]+array3[k]==number) {
count++;
}
}
}
}
System.out.println("组成\"" + number + "\"的次数为" + count);
count = 0;
} else {
System.out.println("请输入0~27之间的数字!");
count = 0;
}
} catch(IOException e) {
e.printStackTrace();
} catch(NumberFormatException e) {
System.out.println("请输入数字!");
}
}
}
}
ladybirds2008 2010-03-24
  • 打赏
  • 举报
回复
还有就是 System.Console.Write();这个好像是write()方法是没有参数的吧。。。
ladybirds2008 2010-03-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 heruoyong 的回复:]
C# code
public static void Main()
{
for (int i = -1; i <= 28; i++)
{
int count = compute(i);
System.Console.WriteLine("Total Count……
[/Quote]这明显是错误的嘛。。System.Console.Write("sum="+sum.ToString()+"="+a[i].ToString()+"+"+b[j].ToString()+"+"+c[k].ToString()+"\t");大小写不分。。。而且 上面int sum 下面来个sum.toString()?还有a[i],b[j],c[k]....太夸张了吧。这错误。。。
scsxd 2010-03-24
  • 打赏
  • 举报
回复
楼上已经回答完毕
heruoyong 2010-03-23
  • 打赏
  • 举报
回复
public static void Main()
{
for (int i = -1; i <= 28; i++)
{
int count = compute(i);
System.Console.WriteLine("Total Count:"+count.ToString());
}
System.Console.ReadLine();
}

public static int compute(int sum)
{
int returnValue = 0;
if (sum > 27 || sum < 0)
{
return returnValue;
}
int[] a = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[] b = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[] c = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

for (int i = 0; i < a.Length; i++)
{
if (a[i] > sum)
{
break;
}
for (int j = 0; j < a.Length; j++)
{
if (b[j] > sum)
{
break;
}
for (int k = 0; k < a.Length; k++)
{
if (c[k] > sum)
{
break;
}
else
{
if (sum == a[i] + b[j] + c[k])
{
returnValue++;
System.Console.Write("sum="+sum.ToString()+"="+a[i].ToString()+"+"+b[j].ToString()+"+"+c[k].ToString()+"\t");
}
}
}
}
}
return returnValue;
}
码之魂 2010-03-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 guoyueshan 的回复:]

穷举法,嵌套3个循环即可搞定
[/Quote]

没什么好说的了.....
guoyueshan 2010-03-23
  • 打赏
  • 举报
回复
穷举法,嵌套3个循环即可搞定
readfuture 2010-03-23
  • 打赏
  • 举报
回复
好帖啊。

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧