| ||||||||||
| 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 | |||||||||
NB,这也能ac,而且把注释掉的初始化部分加上去还变RE....#include <iostream>
using namespace std;
int chess[205];
int step[205],n;
double p[2024][205];
void correct(int &num)
{
while(num < 0 || num > n)
{
if (num < 0)
num = -num;
else if (num > n)
num = 2*n-num;
}
}
int main()
{
int i,nb,nf,ns,num,round,pos,dice,top,j;
while(scanf("%d",&n) == 1)
{
memset(chess,-1,sizeof(chess));
scanf("%d",&nf);
for (i = 0; i < nf; i++)
{
scanf("%d",&num);
chess[num] = 3;
scanf("%d",&step[num]);
}
scanf("%d",&nb);
for (i = 0; i < nb; i++)
{
scanf("%d",&num);
chess[num] = 1;
scanf("%d",&step[num]);
}
scanf("%d",&ns);
for (i = 0; i < ns; i++)
{
scanf("%d",&num);
chess[num] = 2;
}
/*
for (i = 0; i <= top; i++)
{
for (j = 0; j <= n; j++)
{
p[i][j] = 0;
}
}
*/
double once = 1.0/6.0;
p[0][0] = 1;
top = 1000;
for (round = 0; round <= top; round ++)
{
for (pos = 0; pos < n; pos++)
{
if (p[round][pos] > 0)
{
for (dice = 1; dice <= 6; dice ++)
{
int next = dice+pos;
correct(next);
if (next >= 0 && next <= n)
if (chess[next] == -1)
{
p[round+1][next] += (p[round][pos])*once;
}
else if (chess[next] == 1)
{
next -= step[next];
correct(next);
if (next >= 0 && next <= n)
p[round+1][next] += (p[round][pos])*once;
}
else if (chess[next] == 2)
{
p[round+2][next] += (p[round][pos])*once;
}
else if (chess[next] == 3)
{
next += step[next];
correct(next);
if (next >= 0 && next <= n)
p[round+1][next] += (p[round][pos])*once;
}
}
}
}
}
double ans = 0;
for (i = 0; i <= top; i++)
{
ans += p[i][n]*i;
}
if (ans > 0)
printf("%.2lf\n",ans);
else printf("Impossible\n");
}
return 0;
}
/*
1
0
0
0
*/
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator