66 exam simulation summary

T1 think the exam is math, subtract multiply mediated by something, then hit the table to find the law 1h, no tension and spent 1h fine tune the increase,

There are more than 1h and then write a written T2T3 violence, T2 thought did a simulated T1 42, but did not think carefully, so I did not expect bitset

A T1 is not that the bottom, so very relaxed, but also to enhance the

T1 "wrong row of problems"

Look at the skyh blog, I did not understand,  

References Baidu Encyclopedia:

Order is a Staggered, if each element not in its corresponding position on the subject, i.e. , so this arrangement is called a derangement or Staggered, rearrangement (Derangement).

We start from the wrong row 1234 analysis:
1 2 3 4 Staggered there is:
4 3 2 1,4 1 2 3,4 3 1 2,
3 4 1 2,3 4 2 1,2 4 1 3,
2 1 4 3,3 1 4 2,2 3 4 1。
4 The first column is interchanged position 123, respectively, and the remaining two elements Staggered.
1 2 3 4->4 3 2 1,
1 2 3 4->3 4 1 2,
1 2 3 4-> 2 1 4 3
The second column of each number 312 4, respectively (a Staggered 123) interchange
3 1 2 4->4 1 2 3,
3 1 2 4->3 4 2 1,
3 1 2 4->3 1 4 2
The third column is 231 and by another 4 Staggered obtained transposition
2 3 1 4->4 3 1 2,
2 3 1 4->2 4 1 3,
2 3 1 4->2 3 4 1
The above analysis results, in fact, the result is to give a Staggered generated.

f[n]=(n-1)*f[n-1]+(n-1)*f[n-2]

The first column is the first case 123 swap positions 4, respectively, and the remaining two elements Staggered: (n-1) * f [n-2]

4 n-1 is capable of changing the number of the previous position, f [n-2] is a row n-2 mismatches

Similarly the two is (n-1) * f [n-2]

 

T2【bitset】【BFS】

Each point can be used to maintain bitset set of points, n ^ 2 violence

Correct

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<vector>
 4 #define R register
 5 using namespace std;
 6 inline int min(int x,int y){
 7     return x<y?x:y;
 8 }
 9 const int maxn=2048;
10 int n;
11 int a[maxn][maxn],b[maxn][maxn];
12 char ch[maxn];
13 int tot,dfn[maxn],low[maxn];
14 int cnt,ins[maxn];
15 int top,sta[maxn];
16 int vis[maxn];
17 void init(){
18     top=cnt=tot=0;
19     for(int i=1;i<=n;++i) vis[i]=ins[i]=dfn[i]=low[i]=0;
20 }
21 void tarjan(int x,int ff){
22     dfn[x]=low[x]=++tot;
23     sta[++top]=x,ins[x]=1;
24     vis[x]=1;
25     for(int y=1;y<=n;++y){
26         if(ff==1&&!a[x][y]&&!b[x][y])continue;
27         if(ff==2&&!a[x][y]&&!b[y][x])continue;
28         if(!dfn[y]){
29             tarjan(y,ff);
30             low[x]=min(low[x],low[y]);
31         }
32         else if(ins[y])
33             low[x]=min(low[x],dfn[y]);
34     }
35     if(dfn[x]==low[x]){
36         int y;++cnt;
37         do{
38             y=sta[top--];
39             ins[y]=0;
40         }while(y!=x);
41     }
42 }
43 int main(){
44    // freopen("data","r",stdin);
45     int T;scanf("%d",&T);
46     while(T--){
47         scanf("%d",&n);
48         for(int i=1;i<=n;++i){
49             scanf("%s",ch+1);
50             for(int j=1;j<=n;++j){
51                 a[i][j]=b[i][j]=0;
52                 if(ch[j]=='P')a[i][j]=1;
53                 if(ch[j]=='Q')b[i][j]=1;
54             }
55         }
56         init();
57         for(int i=1;i<=n;++i)
58             if(!vis[i]) tarjan(i,1);
59         if(cnt!=n){puts("N");continue;}
60         init();
61         for(int i=1;i<=n;++i)
62             if(!vis[i])tarjan(i,2);
63         if(cnt!=n){puts("N");continue;}
64         puts("T");
65     }
66 }
View Code

 

Guess you like

Origin www.cnblogs.com/casun547/p/11643977.html