Yale-Yale Study 10.7

Source: Internet
Author: User

Yale-Yale Study of the 10.7-morning exam questions

Full TM Fairy question ...

\ (t1\) \ (35\) divided violence

\ (t2\) i \ (n=1\) when the direct output of \ (1\), even if there is no block on this lattice is not sentenced, it was feeling ... Is this part of the card?

The result is that the person is so stuck. I don't have a penny.

It's too malignant.

\ (t3\) successful cheat \ (8\) points

After doing a period of time to do the cattle network.
I have a violent fight with people.
And then I TM. From purple name to Gray name????

Title and examination Room Code T1

*/* Violence: BFS starting from initial position */#include <queue> #include <cstdio> #include <algorithm>const int n=100001;int    N,k,m,s,a[n],dis[n];bool ban[n];std::queue<int> que;void Add (int x,int y) {if (x+y<=n &&!ban[x+y])        {Que.push (x+y);        Ban[x+y]=true;    dis[x+y]=dis[x]+1;        } if (x-y>0 && ban[x-y]==false) {que.push (x-y);        Ban[x-y]=true;    dis[x-y]=dis[x]+1;    }}void solve () {Que.push (s);    Ban[s]=true;        while (!que.empty ()) {int U=que.front (); for (int i=1;i<=k;++i) {if (!) (            k&1) && i&1) Add (u,i); if (k&1 &&!) (        i&1)) Add (u,i);    } que.pop ();     }}int Main () {freopen ("reverse.in", "R", stdin);    Freopen ("Reverse.out", "w", stdout);    scanf ("%d%d%d%d", &n,&k,&m,&s);        for (int x,i=1;i<=m;++i) {scanf ("%d", &x);    Ban[x]=true;     } if (k==1) {   for (int i=1;i<=n;i++) if (i==s) printf ("0");        else printf ("-1");    Goto E;    } solve ();            for (int i=1;i<=n;++i) {if (dis[i]==0) if (i==s) printf ("0");        else printf ("-1");    else printf ("%d", dis[i]);    }e:fclose (stdin), fclose (stdout); return 0;}
T2

#include <cstdio>inline int read(){    int n=0,w=1;register char c=getchar();    while(c<'0' || c>'9'){if(c=='-')w=-1;c=getchar();}    while(c>='0' && c<='9')n=n*10+c-'0',c=getchar();    return n*w;}const int N=1e5+1;int n,a[N],b[N];int main(){    freopen("silhouette.in","r",stdin);    freopen("silhouette.out","w",stdout);    n=read();    for(int i=1;i<=n;++i)a[i]=read();    for(int i=1;i<=n;++i)b[i]=read();    if(n==1)    {        printf("1");        goto E;    }E:  fclose(stdin);fclose(stdout);    return 0;}
T3

/* */#include <cstdio>int n,p;inline int ksm(long long n,int b){    long long res=1;    for(;b;b>>=1,n=n*n%p)        if(b&1)            res=res*n%p;    return res;}int main(){    freopen("seat.in","r",stdin);    freopen("seat.out","w",stdout);    scanf("%d%d",&n,&p);    if(n==1)        printf("1");    else        if(n==2)        {            int o=ksm(2,p-2);            printf("%d %d\n",o,o);            printf("%d %d\n",o,o);            return 0;        }        else    printf("19260817");    fclose(stdin),fclose(stdout);    return 0;}
Positive solutions and Code T1

Considering which points can be transferred to each point at a time by one rollover, direct \ (bfs\) calculates the required number of steps for each point. However, the number of sides will reach the \ (O (n^2) \) level.
It can be found that the transferred point must be an odd or even number within a certain interval, so a simple optimization method is to open two \ (set\) at \ (bfs\ ) to maintain which odd and even points have not been bfs\ to, When transferring directly on \ ( set\ ) \ (lowerbound\), you will not be able to access points already \ (bfs\) .

\ (O (n\log n) \)

#include <bits/stdc++.h> #define for (I, J, K) for (int i = j; I <= K; i++) using namespace std;const int N = 1e5 +    10;int N, K, M, s;int dis[n];bool ban[n];set<int> Odd, even;void BFS () {memset (DIS,-1, sizeof dis);    Queue<int> Q;    Dis[s] = 0, Q.push (S);        while (!q.empty ()) {int o = Q.front (); Q.pop ();        int L = max (1, o-k + 1), R = Min (n, O + K-1);        L = L + (l + K-1)-O, R = r + (r-k + 1)-O; Set<int> &p = L & 1?        Odd:even; for (Auto i = P.lower_bound (L); I! = P.end () && *i <= R; p.erase (i++)) dis[*i] = Dis[o] + 1, Q.push (    *i);    }}int Main () {freopen ("reverse.in", "R", stdin);    Freopen ("Reverse.out", "w", stdout);    scanf ("%d%d%d%d", &n, &k, &m, &s);        For (I, 1, m) {int x;        scanf ("%d", &x);    Ban[x] = true; } for (I, 1, N) if (!ban[i] && i! = S) I & 1?    Odd.insert (i): Even.insert (i);    BFS (); For (i, 1, N) printf ("%d%c", dis[i], i = = n?    ' \ n ': '); return 0;}
T2

Topic Conversion:

is actually asking how many nonnegative integer solutions are in the following equation group:
\[\forall i\in [1,n],\max_{j=1}^n x_{i,j}=a_i,\max_{j=1}^n x_ (j,i) =b_i\]
Then you might want to sort \ (a,b\) , which obviously doesn't have any effect. If \ (A_\max\ne b_\max\) Then the answer is \ (0\), otherwise there must be a solution

Obviously there \ (X_{i,j}\le \min (a_i,b_j) \), from the large to the small enumeration each \ (a,b\) appears in the value \ (s\), each time determine all \ (\min (a_i,b_j) = s\) The value of the position of the

    1. First consider the case where \ (s\) is the maximum value, at which point we want to determine the position that constitutes a rectangle. We can find that we want to solve such a sub-problem: a \ (a\times b\) rectangle, the value of each position in \ ([0,s]\) , and the maximum value of each column per row is \ (s\), The scenario in which you need to calculate how many values are taken.
      Consider the allowance, set \ (f (i) \) for a scenario where the limit of at least \ (i\) rows does not satisfy the condition (need to ensure that each column satisfies the condition), then there is

\[f (i) ={a\choose i} (S^i\times ((s+1) ^{a-i}-s^{a-i}) ^b scheme number is \sum_{i=0}^a ( -1) ^i f (i) \]

方案数就是$\sum_{i=0}^a(-1)^i f(i)$
    1. \ (s\) is not the maximum value, each time we want to determine the position may be \ (' L ' \) shape, still can be used in the same way to the repulsion

Plus fast exponentiation inverse, total complexity \ (O (n\log n) \)

#include <bits/stdc++.h> #define for (I, J, K) for (Int. i = j; I <= K; i++) #define Forr (I, J, K) for (int i = j; i >= K;    i--) using namespace std;const int N = 5e5 + 10;const int Mod = 1e9 + 7;int Pow (int x, long long e) {int ret = 1;        while (e) {if (E & 1) ret = 1LL * RET * x% Mod;        x = 1ll * x * x% Mod;    e >>= 1; } return ret;}    int Fac[n], rfac[n];int work (int A, int b, int la, int lb, int w) {int ans = 0;        For (i, 0, a) {int s = POW (POW (w + 1, la + a-i)-Pow (w, la + a-i) + Mod, b);        s = 1ll * S * POW (w + 1, 1ll * lb * (a-i))% mod * Pow (W, 1ll * (b + lb) * i)% mod;        s = 1ll * s * rfac[i]% mod * rfac[a-i]% mod; if (I & 1) ans = (ans-s + mod)% MoD;    else ans = (ans + s)% Mod; } return 1ll * ans * fac[a]% Mod;}    int a[n], b[n], num[n << 1];int N, C;int Main () {freopen ("silhouette.in", "R", stdin);    Freopen ("Silhouette.out", "w", stdout);    scanf ("%d", &n); For(I, 1, N) scanf ("%d", &a[i]), num[++c] = a[i];    For (i, 1, N) scanf ("%d", &b[i]), num[++c] = b[i];    Fac[0] = 1;    For (i, 1, n) fac[i] = 1LL * fac[i-1] * I% Mod;    Rfac[n] = Pow (Fac[n], Mod-2);    Forr (i, N, 1) rfac[i-1] = 1LL * rfac[i] * I% Mod;    Sort (A + 1, a + n + 1, greater<int> ());    Sort (b + 1, B + n + 1, greater<int> ());    Sort (num + 1, num + C + 1, greater<int> ());    c = Unique (num + 1, num + C + 1)-num-1;    int la = 0, lb = 0;    int ans = 1;        For (I, 1, c) {int ra = LA, rb = lb;        while (RA < n && a[ra + 1] = = Num[i]) ++ra;        while (RB < n && b[rb + 1] = = Num[i]) ++rb;        Ans = 1ll * ans * work (Ra-la, rb-lb, LA, LB, num[i])% Mod;        if (ans = = 0) break;    La = ra, lb = RB;    } printf ("%d\n", ans); return 0;}
T3

One conclusion is that for any one person, the distance from the nearest person when he sits down is fixed and does not change with the decision of the previous person. In this way we can divide all the people by the distance they sit down into several layers. Another conclusion is that, regardless of how each layer is made, the 逬 of the length of the empty interval at the turn of the layer is fixed.
For the last layer of special processing, the next default is not the last layer. For each of the previous layers, consider which empty
The central part of the interval is the maximum distance, which may have some odd-length intervals and some even-numbered intervals, while for each person, the probability of sitting in the center of any odd number of intervals is equal, even the same.
Then we just need to know how much each person has the chance to sit in the middle of an odd or even interval. Consider \ (dp[i][j]\) that this layer has sat down \ (i\) Individuals, there is a \ (j\) length of an even number of interval probability, transfer only to consider the current person sitting in what kind of interval. \ (dp\) It is easy to calculate the probability of the previous request.

When the interval length is odd, the position is fixed, considering the case where the interval length is even, there are two positions available
Choice, but whichever you choose, divides the interval into two segments of length \ (\frac{n}{2}\) and \ (\frac{n}{2}-1\) . So the two choices are symmetrical, and we just have to assume that one of them is chosen, and the answer to the layer after that is given in this case, and the answer to the other case can be presented symmetrically.
The bottleneck in the use of symmetry to push the answer where the complexity of \ (O (n^2\log n) \)

#include <bits/stdc++.h> #define for (I, J, K) for (Int. i = j; I <= K; i++) #define Forr (I, J, K) for (int i = j; i >= K;    i--) using namespace std;const int N = 1030;int mod;int Pow (int x, int e) {int ret = 1;        while (e) {if (E & 1) ret = RET * x% Mod;        x = x * x% Mod;    e >>= 1; } return ret;}    void Add (int &x, int y) {x + = y; x = x >= Mod? x-mod:x;} int N;int dp[n][n], f[n][n], G[n][n];bool vis[n];int inv[n], cnt[n], Odd[n], Pos[n];int main () {freopen ("seat.in", "R"    , stdin);    Freopen ("Seat.out", "w", stdout);    scanf ("%d%d", &n, &mod);    For (i, 1, n) inv[i] = Pow (i, Mod-2);    Vis[0] = vis[n + 1] = true;        For (i, 1, n) {int PL = 0, pr = 0;            For (j, 0, N) {int r = j + 1;            while (!vis[r]) ++r;            if (r-j > pr-pl) PL = J, pr = R;        j = r-1;        } int mx = (PR-PL)/2;        cnt[mx]++;        Pos[i] = pl + mx; VIS[PL + MX]= true;    if ((PR-PL)% 2) odd[mx]++;    } int sum = n;        For (i, 1, N) if (Cnt[i]) {int L = Sum-cnt[i] + 1, r = sum;        if (i = = 1) {for (J, L, R) for (K, L, R) dp[j][pos[k] [= Inv[cnt[i]];            } else {for (J, 0, Cnt[i]) for (k, 0, Odd[i]) f[j][k] = 0;            F[0][odd[i]] = 1;            int p = l + odd[i]-1;                For (J, 1, Cnt[i]) {int ODDW = 0, evenw = 0;                    For (k, 0, Odd[i]) if (F[j-1][k]) {int frac = (Cnt[i]-j + 1) + k, w = 0;                        if (k) {w = f[j-1][k] * k * 2 mod * Inv[frac]% mod;                        ODDW = (oddw + w * inv[odd[i] * 2])% Mod;                    Add (F[j][k-1], W); } if (Cnt[i]-odd[i]) {w = f[j-1][k] * (frac-2 * k)% Mod * Inv[frac]% Mo                        D         Evenw = (evenw + w * inv[cnt[i]-odd[i]])% Mod;               Add (F[j][k], W);                }} for (U, L, p) Add (Dp[l + j-1][pos[u]], ODDW), add (Dp[l + j-1][pos[u] + 1], ODDW);            for (U, p + 1, R) Add (Dp[l + j-1][pos[u]], EVENW);                } for (J, L, p) {int l = pos[j]-i + 1, R = pos[j] + i; For (V, L, R) if (v! = Pos[j]) for (U, R + 1, n) {int s = v < Pos[j]? v + i + 1:v-I, W = dp[u][v                    ] * Inv[2]% Mod;                Add (G[u][v], W), add (G[u][s], W);            } for (V, L, R) for (U, r + 1, n) dp[u][v] = G[u][v], g[u][v] = 0;    }} sum = L-1; } for (int i = 1; I <= n; i++) for (int j = 1; J <= N; j + +) printf ("%d%c", dp[i][j], j = = n?    ' \ n ': '); return 0;}
Afternoon Lectures Example 1

\ (berland\) to hold \ (n\) Tournament, the first time there is only one person, then each time will be new to join a person. There are \ (k\) Sports in the tournament, everyone in this \ (k\) kind of project has a capacity value, each time will choose any two people who have not been eliminated to carry out a project of the competition, the ability of high-value people to win, the loser is eliminated, until only one person to become the Crown
Army.
Give each individual the ability value of each project to ensure that they are 22 different and how many people in each tournament may become champions.

\ (N\le 5e4,k\le 10\)

Solution:

As long as the player \ (a\) on a project than the player \ (b\) Strong,\ (a\) can be eliminated \ (b\), we can connect a \ (a\) to \ (b\) the Edge.
For the whole graph to find strong connected components, after the contraction point will certainly form a competition chart (any two points have a forward edge), the topological sequence of the most forward component of all the points may become champions.
Each time a point is added, we may need to combine the topological order to strongly connect components within a certain interval. By maintaining each strongly connected component in topological order with \ (set\) , the size of each component is recorded, and the maximum and minimum capability value on each item can be found directly on \ (set\) to find the interval that needs to be merged. Only merge n?1 times,\ (O (nk\log n) \)

Example 2

There are \ (x+y+z\) Individuals, the i\ ( a_i\ ) Individual has a coin, \ (b_i\) a silver coin,\ (c_i\) a penny. Elect \ ( x\) The individual obtains its gold coin, elects \ (y\) individual obtains its silver coin, elects \ (z\) individual obtains its copper coin.

Maximize the total number of coins you receive without repeating the selection of a person. \ (x+y+z\le 10^5\)

Solution:

May I have a shilling\ (a_i=a_i? C_i,b_i=b_i? c_i\), the question becomes elected\ (x\)Individuals receive their coins and elect\ (y\)Individuals get their silver coins, and then add the answer\ (\sum c_i\). By\ (a_i\)Sort from large to small, enumerate the selected\ (x\)Among individuals\ (a_i\)The smallest man, apparently this man before the people were either in the elect of the\ (x\)Individuals, either in the chosen\ (y\)The individual. So we just need to be on each location\ (i\),\ (x\le i\le x+y\)Calculate Two information:\ (i\)Before\ (a_i? b_i\)The largest\ (x\)Individual's\ (a_i? b_i\)The And,\ (i\)After\ (b_i\)The smallest\ (z\)Individual's\ (b_i\)The sum. So we just have to sweep from the back and use small Gan to maintain the current\ (a_i? b_i\)The largest\ (x\)Individuals, each adding a person to the top of the heap, and then counting the second message from the back.\ (O (n\log n) \)

Example 3

There is a \ (1\) to \ (n\) arrangement \ (p\), we call a sub-interval to be good, when and only if the values within the sub-range constitute a contiguous paragraph (for example, the arrangement \ (\{1,3,2\},[1,1] , [2,2], [3,3], [2,3],[1,3]\ ] is a good interval).

\ (q\) times, each inquiry \ (l,r\), ask how many \ (l\le l\le r\le r\), meet \ ([l,r]\) is a good interval.

\ (N,q\le 1.2x10^5,tl=7s\)

Solution:

An interval is good when and only if \ ((\max?\min)? ( R?L) =0\). Consider the small-to-large enumeration \ (r\), which maintains a value for each L with a line segment tree. Maintain two stacks, save \ (l\) in each interval ( max\ ) and \ (min\) values, maintain the stack and modify the value of the corresponding interval on the segment tree.
Minimum and minimum values are required on the segment tree, and if the minimum value is \ (0\)(in fact the global minimum must be \ (0\)), the position of all the minimum values is a valid left endpoint for the current \ (r\) . The line tree is then marked with an "answer for the location of all minimums" and maintains the sum of the interval answers.
by pressing \ (r\) on the enquiry, we can query the sum of the interval answers at \ (r\) to answer the questions.

\ (O (n\log n) \)

Example 4

There is a \ (10^5\) initial empty collection. For a collection, if none of the elements \ (x\) satisfies \ (x\gt 0\), or no element \ (x\) satisfies \ (x\lt 0\), it is defined with a graceful degree of \ (0\) Otherwise, its graceful degree equals the smallest positive element minus its largest negative element.
\ (q\) operation, each operation either adds an element to a set within a range, or asks for the sum of the graceful degree of the set within an interval. \ (q\le 5\times 10^4,tl=4s\)

Solution:

Consider the positive and negative elements separately. If each set has positive and negative elements, then the problem is to support interval fetch \ (\min\) and interval summation.
This can maintain the maximum value \ (\max\) and the second largest value \ (\sec\)for each location, as well as the maximum number of values and a fetch \ (\min\) tag. If you want to x\ \ (\min\)Now, discuss the situation:

    • If \ (x\ge \max\) ignores the operation directly
    • If \ (sec\lt x\lt \max\), the maximum value is updated, and the new interval is quickly calculated based on the maximum number of records.
    • If \ (Sec\le x\), direct violence under the transmission. (Available potential energy analysis proves that the number of violent passes is \ (O (q\log n) \) .)

Back to the subject, the only thing to note is that if a set does not have a positive or negative element, it is not counted into its information, and when a set is first added to a positive or negative element, it can be treated violently. \ (O ((n+q) \log n) \)

From the acquaintance to the present, from apathy to care, from rejection to dependence, from unfamiliar to love, from the conviction to doubt guess, from the affection to the injury, from the dazzling rotten to pale, from the same to the separation, from the feeling to feelings, from understanding to blame, from anticipation to frustration, from ecstasy to sorrow

When you try to alienation, when you decide to burn for your ideal, ask yourself, the pressure of life and the dignity of life is more important?

But you can't get what you want in life.
The House of reluctant, preoccupied with mundane entanglements.
When you find that compromise is a thief, it has already stolen your choice.
Fame is but a high fever, regret is closely followed, not good cough.
I can forgive, but I can't stop.
Alone in the night sentimental.
is young frivolous, but pretended vicissitudes.
Who gives you the courage to disguise.
Discarded ideals are like a slap in the face.
Every time you remember a sentence, you get a slap in the face.
Then began to reflect on, hate their own dirty.

Yale-Yale Study 10.7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.