[The Passion] Jizhong --Day11: sucker sucker who encounter problems

Prior statement, not a malicious slander of title, subject suffering borne by the sucker I (I).

55/50/45/0


 

Description


One day, a sketch artist in the forest, suddenly broke out in torrents, he needs to return home as soon as possible, there is a safe
-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

Input of the first line contains two integers R and C (R, C <= 50 ).
The next R lines contains C characters ( ".", "*" , "X", "D" or "S"). Map to ensure that only a "D" and a "S".

Output

Output painter fastest time required to reach home safe, if the artist can not return home safely output "KAKTUS".
 

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

 

Simple broad search, actually I did not have a lot of attention to flood, anyway, the opening of a queue, the first people to flood again.

 1 #include<bits/stdc++.h>
 2 #pragma GCC optimize(3)
 3 using namespace std;
 4 #define f(i,a,b) for(int i=a;i<=b;i++)
 5 const int N=60;
 6 const int T=120;
 7 int r,c;
 8 struct pos{
 9     int x,y,t;
10 }D,S,F;
11 int ma[N][N],t,x[5]={1,0,-1,0},y[5]={0,1,0,-1},vis[N][N];
12 queue<pos> p;
13 queue<pos> q;
14 char a;
15 void out(pos a){
16     cout<<"pos:"<<a.x<<" "<<a.y<<endl;
17     for(int i=1;i<=r;i++){
18         for(int j=1;j<=c;j++){
19             cout<<ma[i][j]<<" ";
20         }
21             cout<<endl;
22     }
23 }
24 int main(){
25     while(!p.empty()) p.pop();
26     while(!q.empty()) q.pop();
27 //    freopen("data1.in","r",stdin);
28     scanf("%d%d",&r,&c);
29     f(i,1,r){
30         f(j,1,c){
31             scanf("%1s",&a);
32             if(a=='D'){
33                 D.x=i,D.y=j;
34                 ma[i][j]=2;
35             }
36             else if(a=='S'){
37                 S.x=i,S.y=j,S.t=1;
38                 ma[i][j]=1;
39             }
40             else if(a=='*'){
41                 p.push((pos){i,j,1});
42                 ma[i][j]=3;
43             }
44             else if(a=='X'){
45                 ma[i][j]=4;
46             }
47             else;
48         }
49     }
50     q.push(S);
51     while(1){
52         t++;
53         pos nowf=p.front();
54         while(nowf.t==t){
55             p.pop();
56             f(i,0,3){
57                 if(nowf.x+x[i]<=0||nowf.x+x[i]>r||nowf.y+y[i]<=0||nowf.y+y[i]>c) continue;
58                 if(!ma[nowf.x+x[i]][nowf.y+y[i]]){
59                     ma[nowf.x+x[i]][nowf.y+y[i]]=3;
60                     p.push((pos){nowf.x+x[i],nowf.y+y[i],t+1});
61                 } 
62             }
63             nowf=p.front();
64         }
65         bool flag=0;
66         pos nowd=q.front();
67         while(nowd.t==t){
68 //            out(nowd);
69             q.pop();
70             f(i,0,3){
71                 if(nowd.x+x[i]<=0||nowd.x+x[i]>r||nowd.y+y[i]<=0||nowd.y+y[i]>c) continue;
72                 if(vis[nowd.x+x[i]][nowd.y+y[i]]) continue;
73                 if(!ma[nowd.x+x[i]][nowd.y+y[i]]){
74                     vis[nowd.x+x[i]][nowd.y+y[i]]=1;
75                     q.push((pos){nowd.x+x[i],nowd.y+y[i],t+1});
76                     flag=1;
77                 }
78                 else if(ma[nowd.x+x[i]][nowd.y+y[i]]==2){
79                     printf("%d",t);
80                     return 0;
81                 } 
82             }
83             nowd=q.front();
84         }
85         if(!flag){
86             printf("KAKTUS\n");
87             return 0;
88         }
89     }
90     return 0;
91 }

 


 

Description

Everyone knows James Bond, the famous 007, but few people know that a lot of his personal mission is not complete, but by his cousin Jimmy Bond had completed (he has a lot cousin), James tired of assign a task to one Jimmy, he turned to you.
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

Input of the first row contains an integer N, the number of tasks and the number of Jimmy Bond (exactly equal, 1 <= N <= 20 ).
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

Maximum output of all tasks of the probability of successful completion, the result retains six decimal places.
 

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

 

At first glance this question, mistaken data 50, no thought Positive solutions (but heard prune the search hit 95 points), is obviously shaped pressure DP, provided f [i] [j] denotes the i-line state the maximum probability j (j has a 1), set S [i] [j] denotes the i-th row in the state of maximum probability of j (j i has a 1), the enumeration line S [i] [ j], to find out the status of the transfer does not conflict maximum value can be.

After Note:

1. your mother, tune to open two hours find an array of small.

2. I heard that this problem can also do with a bipartite graph, when the maximum matching of bipartite graph, using the logarithmic nature of the product and can be turned into logarithms.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=21;
 4 int n;
 5 double sum[2][1<<N];
 6 int num[1<<N];
 7 int mis[N][N],q;
 8 void ini(){
 9     for(int i=1;i<(1<<n);i++){
10         int t=i;
11         int ans=0;
12         while(t){
13             if(t&1) ans++;
14             t>>=1;
15         }
16         num[i]=ans;
17     }
18     for(int i=1,k=1;i<(1<<n);i<<=1,k++){
19         sum[1][i]=mis[1][k];
20     }
21 }
22 int main(){
23     memset(sum,0,sizeof(sum));
24     memset(mis,0,sizeof(mis));
25     memset(num,0,sizeof(num));//毫无卵用
26 //    freopen("data.in","r",stdin);
27     scanf("%d",&n);
28     for(int i=1;i<=n;i++){
29         for(int j=1;j<=n;j++){
30             scanf("%d",&mis[i][j]);
31         }
32     }
33     ini();
34     for(int i=2;i<=n;i++){
35         q=i%2;
36         for(int k=1,l=1;k<(1<<n);k<<=1,l++){
37             for(int j=1;j<(1<<n);j++){
38                 if(num[j]!=i-1||j&k) continue;
39                 sum[q][j|k]=max(sum[q][j|k],sum[q^1][j]*mis[i][l]/100);
40 //                cout<<sum[q][j|k]<<endl;
41             }
42         }
43     }
44     printf("%.6f",sum[q][(1<<n)-1]);
45     return 0;
46 }

Description

You just bought a new house home, want to invite a friend to celebrate, so it is necessary to hold a large dining table, dining table can accommodate the number of people equal to the circumference of the table, you want to buy a can accommodate up to people's dining table, side table must parallel with the side of the room.
To design your room, up to calculate the number of guests invited.
 

Input

The first line contains two integers R and C (1 <= R, C <= 2000), represented by the length and width of the house.
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

Output up to the required number of guests.
 

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
 

Data Constraint

 
 

Hint

[Data size]
50% of the data is R & lt, C <400 =
70% of the data R & lt, C <1000 =
100% of the data, R, C <= 2000

Think of dynamic programming, but when the examination columns wrong.

Positive Solution: Let h [i] [j] represents the point (i, j) position of maximum upward extension, l [i] [j], r [i] [j] can represent a leftward or rightward at the highest position the farthest position reached, with the prefix and pre-click.

I do not know why the memory will be fried, obviously not exceeded.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=2100;
 4 int r,c;
 5 int a[N][N],ans;
 6 int sum[N][N],h[N][N],ll[N][N],rr[N][N];
 7 char t;
 8 int getsum(int x1,int y1,int x2,int y2){
 9     return sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
10 }
11 int main(){
12     scanf("%d%d",&r,&c);
13     for(int i=1;i<=r;i++){
14         for(int j=1;j<=c;j++){
15             scanf("%1s",&t);
16             a[i][j]=(t=='.'?1:0);
17             sum[i][j]=sum[i-1][j]+sum[i][j-1]+a[i][j]-sum[i-1][j-1];
18         }
19     }
20 
21     for(int i=1;i<=r;i++){
22         for(int j=1;j<=c;j++){
23             if(!a[i][j]) continue;
24             for(int l=1;i+l<=r;l++){
25                 if(a[i+l][j]) h[i][j]=l;
26                 else break;
27             }
28         }
29     }
30 
31     for(int i=1;i<=r;i++){
32         for(int j=1;j<=c;j++){
33             if(!a[i][j]) continue;
34             for(int l=1;j+l<=c;l++){
35                 if(getsum(i,j,i+h[i][j],j+l)==(h[i][j]+1)*(l+1)) rr[i][j]=l;
36                 else break;
37             }
38         }
39     }
40 
41     for(int i=1;i<=r;i++){
42         for(int j=1;j<=c;j++){
43             if(!a[i][j]) continue;
44             for(int l=1;j-l>0;l++){
45                 if(getsum(i,j-l,h[i][j]+i,j)==(h[i][j]+1)*(l+1)) ll[i][j]=l;
46                 else break;
47             }
48         }
49     }
50     for(int i=1;i<=r;i++){
51         for(int j=1;j<=c;j++){
52             ans=max(ans,(h[i][j]+1+rr[i][j]+ll[i][j]+1)*2);
53         }
54     }
55     printf("%d",ans-1);
56     return 0;
57 }

Description

Cycling was held in a large place, there are N towns, with numbers 1 to N, there is connected between the M-way street and the town of the town, located in the town of a starting point, the end 2 is provided in the town.
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

The first line of two integers: N and M (1 <= N <= 10000,1 <= M <= 100000), and represents a number of town roads.
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

Output the number of different routes, if the answer is more than 9, only the output of the last nine digits. If there are an infinite number of routes, output "inf".
 

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 

input 3: 
31 is 60 
1. 3 
1. 3 
. 3 . 4 
. 3. 4 
. 4. 5 
. 4. 5 
. 5. 6 
. 5. 6 
. 6. 7 
. 6. 7 
... 
... 
... 
28 29 
28 29 
29 30 
29 30 
30 31 is 
30 31 is 
31 is 2 
31 is 2

Sample Output

Output 1: 
3 

Output 2: 
INF 

Output 3: 
073,741,824

 

Topological sorting sentenced ring + dp compute the answer, do not write a standard process.


Summary: Come on 300 points on the roll to Group A play this game! 250 or else also, is too short, at least two A problem now!

 

Guess you like

Origin www.cnblogs.com/Nelson992770019/p/11332657.html