Prior statement, not a malicious slander of title, subject suffering borne by the sucker I (I).
55/50/45/0
1235. Flood (Standard IO)
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 }
1236. Bond I (Standard IO)
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 }
1237. table (Standard IO)
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 }
1238. bicycle race (Standard IO)
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!