| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Help!why runtime error?thanks!import java.util.*;
public class Main {
static double bestP=0.0;
public static void main(String[] args) {
// TODO 自动生成方法存根
Scanner input=new Scanner(System.in);
while(true)
{
int n=input.nextInt();
int t=input.nextInt();
int l=input.nextInt();
int b=input.nextInt();
if(n==0&&t==0&&l==0&&b==0) break;
int lost[]=new int[l+1];
int back[]=new int[b+1];
for(int i=0;i<l;++i)
lost[i]=input.nextInt();
for(int i=0;i<b;++i)
back[i]=input.nextInt();
new Main().solve(n,t,l,b,lost,back);
}
}
static void DFS(int n,int t,int l,int b,int lost[],int back[],int count,double p,int pos)
{
int j;
if(count>=t)
{
if(count==t&&pos==n)
{
bestP+=p;
return;
}
return;
}
if(count<t)
{
for(int i=1;i<=6;++i)
{
j=pos+i;
if((pos+i)>n) j=n+n-j;
if(j==n)
{
bestP+=(p/6);
continue;
}
boolean flagL=false;
boolean flagB=false;
for(int k=0;k<l;++k)
{
if(lost[k]==j)
{
flagL=true;
break;
}
}
if(flagL)
{
DFS(n,t,l,b,lost,back,count+2,p/6,j);
continue;
}
for(int k=0;k<b;++k)
{
if(back[k]==j)
{
flagB=true;
break;
}
}
if(flagB)
{
DFS(n,t,l,b,lost,back,count+1,p/6,0);
continue;
}
DFS(n,t,l,b,lost,back,count+1,p/6,j);
}
}
}
static void solve(int n,int t,int l,int b,int lost[],int back[])
{
bestP=0.0;
DFS(n,t,l,b,lost,back,0,1,0);
System.out.println(bestP);
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator