Yale-Yale Study 10.3

Source: Internet
Author: User
Tags shuffle

Yale-Yale Study 10.3

The condition of each problem T1

Violence modification + one-dimensional differential + two-dimensional differential

No 49 points to be baffled ...

It seems that the array is not large enough to open?

T2

This... Probabilities and expectations, one will not, even that part of the points are not any ideas

T3

The topic did not read too well.

Wrote an enumeration algorithm and then output the obvious results for a single point of data

。。。

And then he just took 1 points.

Enumeration hangs because it will be wrong the meaning of the topic

Title and examination Room Code T1

/* * Each modification must be timed out. * Q==0 Direct Output 0 * 19 points should be violent * * Consider each operation, calculate the total number of changes in the number of locations * The number of words to let the current answer XOR or this figure * for the boundary of separate discussion * But the problem is ... If the location of the change is just the position of the current answer is larger, it should not be different or, but + * really do not maintain AH * Pretend to write is correct ...    * * per line differential * Last O (n^2) statistics */#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;} inline int min (int x,int y) {return x<y?x:y;}    const INT N=1002;long long Map[n][n],add[n][n],cut[n][n];int main () {freopen ("u.in", "R", stdin);    Freopen ("U.out", "w", stdout);    int N=read (), Q=read (), r,c,s,l,x;    Long Long ans=0;        if (q==0) {printf ("0");    Goto E;            } if (q<=400) {while (q--) {r=read (), C=read (), L=read (), S=read ();            X=min (R+l-1,n);        for (int i=r;i<=x;++i) for (int j=c;j<=min (i-r+c,n); ++j) Map[i][j]+=s;            } for (int i=1;i<=n;++i)for (int j=1;j<=n;++j) ANS^=MAP[I][J]; } else if (q<=2000) {while (q--) {r=read (), C=read (), L=read (), S=re                AD ();                X=min (R+l-1,n);            for (int i=r;i<=x;++i) map[i][c]+=s,map[i][min (i-r+c,n) +1]+=-s;                } for (int i=1;i<=n;++i) {x=0;                    for (int j=1;j<=n;++j) {x+=map[i][j];                    printf ("%d", x);                Ans^=x;            } puts ("");                }} else {while (q--) {r=read (), C=read (), L=read (), S=read ();                Add[r][c]+=s,add[r+l][c]-=s;            Cut[r][c+1]+=s,cut[r+l][c+l+1]-=s; } for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {add[i][j                    ]+=ADD[I-1][J]; Cut[i][j]+=cuT[I-1][J-1]; } for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {map[i][j                    ]+=MAP[I][J-1]+ADD[I][J]-CUT[I][J];                ANS^=MAP[I][J];            }}/* else {while (q--) {r=read (), C=read (), L=read (), S=read ();            x=l+1;                if (R+l-1>n | | c+l-1>n) {//Thought for a long while did not want to come out how quickly to remove the unnecessary parts.                x=0;            for (int i=r;i<=min (r+l-1,n); ++i) x+=min (i-r+c,n);        } if (x&1) ans^=s;            }}*/printf ("%lld", ans);    E:fclose (stdin); fclose (stdout); return 0;}
T2

/* * 概率。。。 * 根本一会不会啊。。。 * 骗分走人 */#include <cstring>#include <cstdio>const int N=31;char s[N];int main(){    freopen("v.in","r",stdin);    freopen("v.out","w",stdout);    scanf("%d%d",&n,&k);    scanf("%s",s);    int x=0;    for(int i=0;i<n;++i)        if(s[i]=='W')            ++x;    if(k==0 || k==n)        printf("%.10lf",(double)1.0*k);    else    printf("%.10lf",(double)x*1.0/2);    fclose(stdin);fclose(stdout);    return 0;}
T3

/* * Output 0 has 1 points. */#include <cstdio> #include <vector>int n,step,cnt,k_2,z_2,ku;int l_note[100023];struct note{int con, Have,wash;}; BOOL dis[100023];std::vector<note> tree[100023];std::vector<int> kuai[100023];void search (int num) {for (        int space,i=0;i<l_note[num];i++) {Space=tree[num][i].con; if ((tree[num][i].wash!=tree[num][i].have) | | | (tree[num][i].wash==2))            &&dis[space]!=true) {Tree[num][i].have=tree[num][i].wash;            ++cnt;            Dis[num]=true;            Search (space);        Break    }}}bool vis[100023];void qk (int num) {vis[num]=true;        for (int i=0;i<kuai[num].size (); ++i) {int space=kuai[num][i];        if (tree[num][i].wash==2) ++k_2;    if (vis[space]!=true) qk (space);    }}int Main () {freopen ("w.in", "R", stdin);    Freopen ("W.out", "w", stdout);    scanf ("%d", &n); if (n<=1000) {for (int a,b,c,d,i=1;i<n;++i) {sCANF ("%d%d%d%d", &a,&b,&c,&d);            Tree[a].push_back ((note) {b,c,d});            ++l_note[a];            Tree[b].push_back ((note) {a,c,d});            ++L_NOTE[B]; if ((c!=d) | | |            (d==2))                {Kuai[a].push_back (b);            Kuai[b].push_back (a);        } if (d==2) ++z_2; } for (int i=1;i<=n;++i) {for (int o=0;o<l_note[i];o++) {if (tree I                    [O].wash!=tree[i][o].have) &&tree[i][o].wash!=2) {dis[tree[i][o].con]=true;                    Search (i);                Break            }}} for (int i=1;i<=n;++i) if (Vis[i]!=true&&kuai[i].size ()!=0)                {++ku;            QK (i);        } step=ku-(Z_2-K_2/2);    printf ("%d%d", step,cnt);    } else printf ("0 0");    Fclose (stdin); fclose (stdout); return 0;}
Positive Solution T1

First glance \ (n\times q\) practice,\ (3e8\) obviously cannot

So consider optimizing it: Differential sequence accesses are not contiguous, so we consider turning it into a continuous

It's over ...

Official Positive solution:

To do a differential at a time, skew the difference, then a triangle can be determined, and then \ (n^2\) sweep over the XOR or

#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=1e3+10;int n,q;ll a[maxn][maxn],b[maxn][maxn],ans;inline void add_a(int x,int y,int v){    if(x<=n&&y<=n)        a[x][y]+=v;}inline void add_b(int x,int y,int v){    if(x<=n&&y<=n)        b[x][y]+=v;}int main(){    freopen("u.in","r",stdin);    freopen("u.out","w",stdout);    scanf("%d%d",&n,&q);    while(q--){        int r,c,l,s;        scanf("%d%d%d%d",&r,&c,&l,&s);        add_a(r,c,s);        add_a(r+l,c+l,-s);        add_b(r+l,c,-s);        add_b(r+l,c+l,s);    }    for(int i=1;i<=n;++i)        for(int j=1;j<=n;++j){            if(i>1)                a[i][j]+=a[i-1][j-1]+a[i-1][j]-a[i-2][j-1];            else                a[i][j]+=a[i-1][j-1]+a[i-1][j];            b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1];            ans^=a[i][j]+b[i][j];        }    printf("%lld\n",ans);    return 0;}
T2

You can get a \ (O (2^n\times n) \) pressure \ (dp\) practice, record whether each ball has not been removed, and then follow the optimal strategy to expect to remove the number of white balls

In fact, there are a lot of repeating states, that is, the remaining color sequence is the same as the result.

Consider the state as the remaining color sequence, the length of the small time directly with the array to save, larger time with \ (map\) to save

The number of states can get an upper bound is \ (\sum_{i=0}^n\min\{2^i,{i\choose n}\}\)(in fact the maximum value is \ (\sum_{i=1}^{n+1}fib_i\) But it's not (noip\))

#include <bits/stdc++.h>using namespace Std;const int maxn=30+5;int n,k;char s[maxn];namespace ${const int XXX=24    ;    Double a[1<<xxx+1];    Map<int,double> M[MAXN];    inline void init () {for (int i=0;i<1<<xxx+1;++i) a[i]=-1;        } inline bool Count (int bit,int len) {if (len<=xxx) return a[1<<len|bit]!=-1;    else return m[len].count (bit);        } inline Double&find (int bit,int len) {if (len<=xxx) return a[1<<len|bit];    else return m[len][bit]; }}inline int erase (int bit,int k) {return bit& (1<<k) -1|bit>>1&-1<<k;} Inline double max_ (double a,double b) {return a>=b?a:b;}    Double dfs (int bit,int len) {if (len<=k) return 0;    if ($::count (Bit,len)) return $::find (Bit,len);    Double&res=$::find (Bit,len);    res=0; for (int i=0,j=len-1;i<=j;++i,--j) if (i<j) Res+=max_ (DFS (ERase (bit,i), len-1) + (bit>>i&1), DFS (Erase (bit,j), len-1) + (bit>>j&1)) * *;    else Res+=dfs (Erase (bit,i), len-1) + (bit>>i&1); return Res/=len;}    int main () {freopen ("v.in", "R", stdin);    Freopen ("V.out", "w", stdout);    $::init ();    scanf ("%d%d%s", &n,&k,s);    K=n-k;    int bit=0;    for (int i=0;i<n;++i) bit|= (s[i]== ' W ') <<i;    printf ("%.10f\n", DFS (Bit,n)); return 0;}
T3

If the last-flipped edge set is \ (s\), the minimum operand is \ (\{v,s\}\) in half the odd number of points, the total length of the minimum operation is \ (| s|\)

Consider the tree \ (dp\),\ (dp[i][0/1]\) records in the subtree with \ (i\) , whether the edge between\ (i\) and father is flipped, the minimum number of odd-numbered points, The minimum total length at this time

#include <bits/stdc++.h>using namespace Std;const int maxn=1e5+10;const pair<int,int> Inf=make_pair (1e9, 1e9) int n;vector<pair<int,int> > G[MAXN];p air<int,int> dp[maxn][2];inline pair<int,int> operator+ (pair<int,int> a,pair<int,int> b) {return make_pair (A.first+b.first,a.second+b.second);}    void Dfs (int pos,int fa,int type) {pair<int,int> tmp0 (0,0), TMP1 (INF);            for (int i=0,v;i<g[pos].size (); ++i) if ((V=g[pos][i].first)!=fa) {DFS (v,pos,g[pos][i].second);            Pair<int,int> Nxt0,nxt1;            Nxt0=min (tmp0+dp[v][0],tmp1+dp[v][1]);            Nxt1=min (tmp1+dp[v][0],tmp0+dp[v][1]);        TMP0=NXT0;TMP1=NXT1; } if (type==0| |    type==2) Dp[pos][0]=min (Tmp0,make_pair (Tmp1.first+1,tmp1.second));    else Dp[pos][0]=inf; if (type==1| |    type==2) Dp[pos][1]=min (Make_pair (tmp0.first+1,tmp0.second+1), Make_pair (tmp1.first,tmp1.second+1)); else Dp[pos][1]=inf;} int MaiN () {freopen ("w.in", "R", stdin);    Freopen ("W.out", "w", stdout);    scanf ("%d", &n);        for (int i=1,a,b,c,d;i<n;++i) {scanf ("%d%d%d%d", &a,&b,&c,&d);        if (d!=2) d= (C!=d);        G[a].push_back (Make_pair (b,d));    G[b].push_back (Make_pair (a,d));    } dfs (1,0,0);    printf ("%d%d\n", dp[1][0].first/2,dp[1][0].second); return 0;}
Afternoon Lectures: Search and pruning

The main topic is only the topic

Example One

There is a \ ([1,2^n]\) arrangement \ (a\{1,\cdots,2^n\}\)

There are \ (n\) operations that can be performed, each of which can be performed at most once. (i\) operations: Divides the sequence from left to right into the \ (2^{n-i+1}\) segment, each section exactly includes the number of \ (2^{i-1}\) , and then swaps the whole two segments.
How many different sequences of operations can be ordered from small to large in the array \ (a\) .
Two sequence of operations are different, when and only if the number of operations is different, or at least one operation is different (different or different in the operating position).

\ (N\le 12\)

Solution:

First of all, any legal sequence of operations, we can change their order, still meet the conditions.
Then the contribution of this class of operations sequence is the factorial of the number of operations.
Now, consider only the sequence of operations in which the type number increments. In the case of the i\ operation, the sequence is divided into segments of size \ (2^{i-1}\) , and if a segment is not incremental and continuous, then the condition is definitely not met. Therefore, after this operation is considered, each segment of size \ (2^i\) should be incremented and contiguous.
When considering the operation of section \ (i\) :

    • If the non-conditional \ (2^i\) size of the segment exceeds \ (2\) , exit directly
    • If it doesn't exist, go straight ahead.
    • If only \ (1\) , swap the two segments of its containing \ (2^{i-1}\) to determine if it is feasible
    • If you have \ (2\) , search for the \ (4\) type Exchange scheme separately
Example Two

Farmer John needs some specific specifications of the wood ( n\) block, the length is not necessarily the same, but he left some large-sized planks ( m\) , the length is not necessarily the same. But John could cut the planks into the specs he needed.
Ask John to get as much wood as he needs.

\ (n\le 1000,m\le 50,lenth\le 32767\)

Solution:

Obviously, the answer is two-point.
Determine if the answer is \ (k\) is feasible, it is obvious that the wood can be sorted, the shortest K-block wood is
Can get.
Then prune:

    • From small to large search the wood to get from which plank, because the long wood limit is larger
    • If the two pieces require the same length of wood, then the source of the search will only need to be enumerated from the source of the former.
    • When the length of a piece of raw material is shorter than the shortest demand, then directly discarded, if the total amount of discarded + required total (\gt\) raw materials, cut off
Example Three

Give a number \ (s\), output all the number of approximations and equals \ (s\)

Altogether \ (t\) inquiry

\ (S\le 2e9,t\le 100\)

Solution:

\ (n=\prod_i p_i^{a^i}\rightarrow \sigma (n) =\prod_i\sum_{j=0}^{a_i}p_i^j\)

Then we can search by enumerating \ (p_i\) and its \ (a_i\)

If the current required \ (s\) can be expressed as a sum of the non-searched prime numbers and \ (1\) , then the previous number and the product of this prime is a legitimate answer

For each \ (p\) that makes \ ((p+1) (p-1) \lt s\) , the enumeration possible \ (a_i\) is recursive

Example Four

A \ (n\times m\) of the grid,\ (k\) color, some of the lattice has been painted a certain color, now need to apply the other grid color, so from the (() \ ) to \ ((n,m) \) each path (each down or to the right) will not have a repeating color. The number of solutions, and the \ (10^9+7\) modulo.

\ (N,m\le 1000,k\le 10\)

Solution:

The number of colors should be greater than or equal to the number of steps,\ (n+m-1\le k\rightarrow n+m\le k+1\le 11\), otherwise puts ("0").
Then search the color of each position, can be pressed to each position of the past color.
Feasibility pruning: The number of unused colors is less than the remaining steps, cut off.
Symmetry pruning: If you apply a non-appearing color, which is equivalent, then just search one of them.

Example Five

Have \ (52\) cards lined up in a row \ (\{0,1\cdots 51\}\), then you can divide them into two halves, and then cross the shuffle (a definite permutation).
After washing the card, there may be an error, a pair of adjacent cards swapped position, but each shuffle at most will make a mistake.
Now give the final order of the cards, ask for a minimum number of washes (guaranteed not to exceed \ (10\)), at least a few mistakes.

Solution:

A property: Determine the number of shuffle, if the final arrangement of the real and do not make mistakes in the final arrangement, there are \ (k\) a different position, then the number of mistakes \ (\lceil\frac{k}{2}\rceil\).

As pruning, enumeration of shuffle times and number of mistakes, run \ (ida^*\)

Example VI

You have recorded the time (number \ (\le 300\)) of all buses ( [0,59]\) arriving in this time period, each of which belongs to a line.

    • The arrival time interval of the same route is the same.
    • Each line reaches at least two vehicles at \ ([0,59]\) .
    • Up to \ (17\) lines

How many lines may be at least

Solution:

A line can be determined by the first, second car.
We can determine the ownership of each car in the order of arrival.
If it's the first car on the line, make him a mark first. (At the same time, it should be in \ ([0,29]\))
If it is a second vehicle, enumerate the tagged vehicles to determine a line and, if feasible, delete the line
All the cars of the road.
In this way, as the depth of search increases, the number of optional vehicles decreases rapidly and the search size decreases.

At the same time, some legitimacy or optimization pruning can be added. For example, as the first car more than the indeterminate car.

Example VII

Given \ (n\) character set is \ (\{a,b,c,\cdots,m\}\) string \ (s_i\), ask for a \ (\{a,b,c,\cdots,m\}\) to \ (\{0,1,2,3,4,5,6,7,8,9,+,\times,=\}\) mapping \ (f\), so that all \ (f (s_i) \) are expressions that are legal and set up.

\ (N\le 1000,5\le | S_i|\le 11\)

Solution:

Search for the higher-constrained \ (+,\times, =\) first.
Then, for each equation, we get the number of bits for each number, calculate the value of the range on either side of the equals sign,
It can be pruned without intersection. As the corresponding relationship is determined, the range will become smaller.
Can choose from the low start search, determine the low value, not equal can be pruned

Yale-Yale Learning 10.3

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.