小学生题,读题比做题还花时间的说。。。
Accepted | 1058 | C++ | 00:00.01 | 392K |
#include<stdio.h>
float ratio[5][5 ];
void solve(int n)
{
int i,c[15 ];
float res;
c[0] = c[n + 1] = 0 ;
for(i = 1; i <= n; i++ )
{
scanf("%d",& c[i]);
c[i]-- ;
}
scanf("%f",& res);
for(i = 1; i < n + 2; i++ )
{
res = res * ratio[c[i - 1 ]][c[i]];
res = res * 100 ;
res = (int)(res + 0.5 );
res = res / 100.0 ;
}
printf("%.2f/n" ,res);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1058.txt","r" ,stdin);
#endif
int t,n;
while(scanf("%d",&t) != EOF)
while(t-- )
{
for(int i = 0; i < 5; i++ )
for(int j = 0; j < 5; j++ )
scanf("%f",& ratio[i][j]);
while(scanf("%d",&n) != EOF && n != 0 )
solve(n);
if(t > 0) printf("/n" );
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0 ;
}
float ratio[5][5 ];
void solve(int n)
{
int i,c[15 ];
float res;
c[0] = c[n + 1] = 0 ;
for(i = 1; i <= n; i++ )
{
scanf("%d",& c[i]);
c[i]-- ;
}
scanf("%f",& res);
for(i = 1; i < n + 2; i++ )
{
res = res * ratio[c[i - 1 ]][c[i]];
res = res * 100 ;
res = (int)(res + 0.5 );
res = res / 100.0 ;
}
printf("%.2f/n" ,res);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1058.txt","r" ,stdin);
#endif
int t,n;
while(scanf("%d",&t) != EOF)
while(t-- )
{
for(int i = 0; i < 5; i++ )
for(int j = 0; j < 5; j++ )
scanf("%f",& ratio[i][j]);
while(scanf("%d",&n) != EOF && n != 0 )
solve(n);
if(t > 0) printf("/n" );
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0 ;
}