Find, find, find friends. |
Time limit : 1000ms, Special time limit:2500ms, Memory Limit: 65536KB |
Total Submit Users: Accepted users : 11 |
problem 11548: No Special Judgement |
Problem description |
Xiao Ming and Xiao Red is a pair of good friends, xiaoming to find a little red play when free. But little red erratic whereabouts let Xiao Ming is very nerve-racking. Little Red living in the community underground there was the anti-Japanese war period left the tunnel, Little red peacetime always like to walk around in these tunnels. Little Red in the neighborhood there are N tunnels out of the entrance, in turn labeled 0 to N-1, Xiao Ming want to know when he went to the community when the small red will be in the tunnel out of the entrance, so he will not go long way. Little Red at the beginning of the d in the entrance, Xiao Ming will arrive after the T units, small red every unit of time will be from her current entrance and exit through the tunnel to the adjacent entrances and exits, if there are multiple entrances and adjacent, then she will wait for the probability of random selection of a move, that is, if there are 3, Then the probability of going to any one is 1/3, and 4 is 1/4. Now give you the whole district tunnel layout, please tell Xiao Ming T unit time after the small red in each entrance probability is how much.
|
Input |
For multiple sets of samples, please process to the end of the file. The first row of each set of samples consists of 3 integers, n (2 <= n <=), D (0 <= D < N), T (1 <= t <= 10^9). Next consists of a matrix of n * n, each element may be 0 or 1, the first row of column J is 1 to indicate that the exit of I is connected with the exit of J. The data guarantees that each entrance is Unicom, and the matrix must be a symmetric matrix, and when I==j, the value of the element must be 0.
|
Output |
For each set of samples, first output a line of case #k:, K starts from 1. Then output n number, indicating the probability of entry and exit 0 to N-1, retain 2 decimal places, separated by a space between the numbers
|
Sample Input |
2 0 20 11 03 1 10 1 11 0 11 1 0 |
Sample Output |
Case #1:1.00 0.00Case #2:0.50 0.00 0.50 |
Problem Source |
Hnu Contest |
Parse: I seem to be using the matrix to do, using the fast power of the matrix
#include <iostream> #include <cstdio> #include <cstring> #include <queue > #define &NBSP;MAX (A, B) a>b?a:b#define min (A, b) a<b?a:b#define Max 1000000000USING&NBSP;NAMESPACE&NBSP;STD;INT&NBSP;N,D,T;DOUBLE&NBSP;S[55][55],SUM[55][55];VOID&NBSP;CMP (double (*a) [55],double (*b) [55])//matrix A multiplied by matrix B and then stored in a {//with degrees Niang greetings for half a day, also did not find an optimized calculation method, only this n^3, or hug to see if the idea of a timeout to submit. int i,j,k,l; double c[55][55]={0}; for (i=0;i<n;i++) for (j=0;j<n;j++) if (a[i][j]>0)// It's a pruning, too. { for (k=0;k<n;k++) c[i][k]+=a[i][j]*b[j][k]; } for (i=0;i<n;i++)//Save the results in a inside to for (j=0;j<n;j++) a[i][j] =C[I][J];} VOID&NBSP;KSM ()//Standard FastPower, like to bring home { int i,j,k,l; memset (sum,0,sizeof (sum)); sum[d][d]=1;//beginning in D, then recorded in Sum[d][d] while (t>0) { if (t%2==1) CMP (sum,s); &NBSP;&NBSP;&NBSP;T/=2;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CMP (s,s); }}int main (void) { int i,j,k,l,cas=1; double c; while (scanf ("%d%d%d", &n,&d,&t)!=eof) { for (i=0;i<n;i++) { c=0; for (j=0;j<n;j++) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%lf", &s[i][j]); c+=s[i][j]; } if (c) for (j=0;j<n;j++) s[i][j]/=c; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;KSM (); printf ("case #%d:\n", cas++); for (i=0;i<n;i++)//I do not know how to drop all the results only the first row of data, it should be the characteristics of the Matrix bar. printf ("%.2lf%c", sum[d][i],i==n-1? \ n ': ' '); } return 0;}
hunnu--11548--looking for a friend.