T1 flood
Description
-wide.
Map forest by R rows C composed of columns, a blank area of the point. "" Indicates, the area floods with "*" indicates that, while the
rock with an "X", another artist's residence with "D" represents the artist with "S "means.
The following points should be noted:
1, every minute of the painter can move one space to the four directions (up, down, left, right)
2, every minute of the flood can spread to the four directions of the adjacent grid (blank area)
3, floods and painters can not rock the region
4, the painter can not flood the area (at the same time does not work, that the artist can not be moved to a grid, the grid while the painter was reached to spread the flood, which is not allowed)
5 floods spread less than residence painters.
Give you a map of the forest, programming output at least how long it takes to get home from the starting position.
Input
The next R lines contains C characters ( ".", "*" , "X", "D" or "S"). Map to ensure that only a "D" and a "S".
Output
Sample Input
Input. 1: . 3. 3 D. * ... . .S Input 2: . 3. 3 D. * ... ..S input. 3: . 3. 6 D ... *. .XX. .... S.
Sample Output
Output 1: 3 Output 2: Kaktus output 3: 6
Examination room ideas / positive solution
Very bare BFS, attendance problems.
Code
#include<cstdio> #include<algorithm> #define MAXN 2525 #define INF 2e9 using namespace std; int r,c,sx,sy; int time[55][55],book[55][55],Next[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; char tu[55][55]; struct thm { int x; int y; int bs; }art[MAXN],flood[MAXN]; void Flood(int x,int y) { int s=0,t=1,tx,ty; flood[1].x=x,flood[1].y=y; while(s<t) { s++; for(int i=0;i<4;i++) { tx=flood[s].x+Next[i][0]; ty=flood[s].y+Next[i][1]; if(tx<1 || ty<1 || tx>r || ty>c || tu[tx][ty]=='D' || tu[tx][ty]=='X' || time[tx][ty]!=INF) continue; flood[++t].x=tx; flood[t].y=ty; time[tx][ty]=flood[t].bs=flood[s].bs+1; } } } int main() { scanf("%d%d",&r,&c); for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) time[i][j]=INF; for(int i=1;i<=r;i++) scanf("%s",tu[i]+1); for(int i=1;i<=r;i++) { for(int j=1;j<=c;j++) { if(tu[i][j]=='S') sx=i,sy=j; if(tu[i][j]=='*') time[i][j]=0,Flood(i,j); } } int s=0,t=1,tx,ty; art[1].x=sx,art[1].y=sy; book[sx][sy]=1; while(s<t) { s++; if(tu[art[s].x][art[s].y]=='D') return printf("%d",art[s].bs),0; for(int i=0;i<4;i++) { tx=art[s].x+Next[i][0]; ty=art[s].y+Next[i][1]; if(tx<1 || ty<1 || tx>r || ty>c || art[s].bs+1>=time[tx][ty] || tu[tx][ty]=='X' || book[tx][ty]==1) continue; art[++t].x=tx; art[t].y=ty; art[t].bs=art[s].bs+1; book[tx][ty]=1; } } printf("KAKTUS"); return 0; }
T2 Bond I
Description
Every month, James will receive a number of tasks, based on the experience of his mission before he calculated the completion of each task every Jimmy success rate, it requires that each task must be assigned to different people to complete, each person only to complete a task.
Please write a program to find a probability distribution plan so that all tasks are completed successfully.
Input
Next N rows, each row contains an integer number between 0 and 100 N, the number of the i-th row j Aij Jimmy Bond i indicates the probability of success of task j Aij%
Output
Sample Input
Input 1: 2 100 100 50 50 Input 2: 2 0 50 50 0 Input 3: 3 25 100 60 13 is 0 50 12 is 70 90
Sample Output
Output 1: 50.000000 Output 2: 25.000000 Output 3: 9.100000
Examination room ideas / positive solution
Like pressure DP, although not played before, but relying on prior knowledge of this concept, the success of the examination room came up positive solution, but it is no AC, because when I tune the code to a half, I suddenly remembered last night's training yeqiao words, and yesterday's tragic events from high AC a problem others might as four Aspects of violence (in fact, in fear of yeqiao from the depths of the soul) , so they play with the rest of the violence, the results of the exam, out slightly change it to AC, and silent.
Since n <= 20, so we can record whether the i-th task in individuals 20 01 string. Therefore, we can set f [01 string] where cost is represented by the position of a person, the optimal benefit of the pre-processed I (number 1) is. Equations can be imagined.
Code
#include<cstdio> #include<algorithm> using namespace std; int n; int jl[1058576],g[1058576]; double f[1058576]; double gl[22][22]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%lf",&gl[i][j]),gl[i][j]/=100; jl[1]=1;f[1]=gl[1][1]; for(int i=2;i<=n;i++) jl[i]=jl[i-1]*2,f[jl[i]]=gl[i][1]; int sl1=n,sl2=0; for(int i=2;i<=n;i++) { for(int j=1;j<=n;j++) for(int k=1;k<=sl1;k++) if(!((jl[k]>>(j-1))&1)) if(f[jl[k]|(1<<(j-1))]<f[jl[k]]*gl[j][i]) if(f[jl[k]|(1<<(j-1) )]) f[jl[k]|(1<<(j-1) )]=f[jl[k]]*gl[j][i]; else g[++sl2]=jl[k]|(1<<(j-1) ),f[g[sl2]]=f[jl[k]]*gl[j][i]; for(int j=1;j<=sl2;j++) jl[j]=g[j],g[j]=0; sl1=sl2,sl2=0; } printf("%.6lf",100*f[(1<<n)-1]); return 0; }
T2 table
Description
To design your room, up to calculate the number of guests invited.
Input
Next R S lines each character (no spaces), "." Indicates a blank area, "X" indicates an obstacle, the area occupied by the table must be empty.
Output
Sample Input
Input 1: 22 .. .. Input 2: . 4. 4 X.XX X..X .. X-. ..XX input. 3: . 3. 3 XX . .X XX
Sample Output
Output 1: 7 Output 2: 9 output 3: 3
Hint
50% of the data is R & lt, C <400 =
70% of the data R & lt, C <1000 =
100% of the data, R, C <= 2000
Examination room ideas
Correct
Monotonous stack, like this thing, very good understanding.
Code
#include<cstdio> #include<algorithm> #define INF 2e9 using namespace std; int r,c,Min,zx,ans; int tu[2002][2002]; char ch[2002]; int main() { scanf("%d%d",&r,&c); for(int i=1;i<=r;i++) { scanf("%s",ch+1); for(int j=1;j<=c;j++) if(ch[j]=='.') tu[i][j]=1; } for(int i=r-1;i>=1;i--) for(int j=1;j<=c;j++) if(tu[i+1][j] && tu[i][j]) tu[i][j]=tu[i+1][j]+1; for(int i=1;i<=r;i++) { for(int j=1;j<=c;j++) { if(!tu[i][j]) continue; Min=INF,zx=j; while(tu[i][zx]) { Min=min(Min,tu[i][zx]); ans=max(ans,2*(Min+zx-j+1)-1); zx++; } } } printf("%d",ans); return 0; }
T4 bike racing
Description
Q. How many different routes from start to finish, a total of. Two routes they do not use exactly the same road are considered to be different.
Input
Next M rows, each row comprising two different integers A and B, represented with a one-way street from town A to town B, respectively.
There may be more than one road connection between the two towns.
Output
Sample Input
Input 1: . 6. 7 1. 3 1. 4 . 3 2 . 4 2 . 5. 6 . 6. 5 . 3. 4 Input 2: . 6. 8 1. 3 1. 4 . 3 2 . 4 2 . 5. 6 . 6. 5 . 3. 4 . 4. 3
Sample Output
Output 1: 3 Output 2: INF
Examination room ideas
Not just violence. .
Correct
We are explored. .
to sum up
There is still a lot of knowledge found himself blind, is much more than make up brush problem, or how big brother than shy .