Yale-Yale Study 10.5

Source: Internet
Author: User

Yale-Yale 10.5 Morning examination of the situation T1

Analog hangs into \ (10\) points??

Each time the answer is updated, the position is mistaken.

Thought of May be the line segment tree dynamic open point, but did not write out, because the mark does not pass ...

T2

Understand the wrong meaning of the topic.

Selected \ (m\) items, at least \ (k\) is \ (a\) like, at least \ (k\) is \ (b\) like

Then it is clear that as long as the above restrictions are met, both people do not like the choice can also ...

But I didn't think this floor was in the exam room.

It's cold.

Positive solution to cheat points,\ (15\) points

T3

After finishing the above two topics there is not much time left, just throw a thing up.

I don't know what it's written about.

Title and examination Room Code T1


/* * First feeling is line tree * Think, feel the line tree is too wasted, bitset should be able to do * but ... After looking at the data * 01 sequence of length 10^18 * this. Do it, do it. * * The third operation is 0 change to 0 * * For n,m<=1000 data, you can simulate * for only 1 operation, consider maintaining the dividing point of all 0 intervals and all 1 intervals * for only 1, 2 operation cases, because is forced into 0 or 1, so also only consider the demarcation point * for n&lt ; =10^5, should the line tree be able? But will not be maintained. */#include <cstdio> #include <algorithm>inline long Long read () {long n=0;int w=1;register char C=getch    AR ();    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 M=1e5+1,qwq[]={0,0,1};int a[100001],ty[m];long long l[m],r[m];std::p air<int,int> pr[M];int Main () {fre    Open ("A.in", "R", stdin);    Freopen ("A.out", "w", stdout);    int M,flag=0;long long n=0;    M=read ();        for (int i=1;i<=m;++i) {ty[i]=read (), L[i]=read (), R[i]=read ();        N=std::max (N,r[i]);    Flag=std::max (Flag,ty[i]);        } if (flag==1) {int id=1,cnt=0; for (int i=1;i<=m;++i) {if (L[i]<=id && r[i]>=id)           {int x=r[i]+1;                for (int j=1;j<i;++j) if (l[j]<=x && r[j]>=x) x=r[j]+1;            Id=x;        } printf ("%d\n", id);            }} else if (n<=100000) {int id=1;                    for (int x,i=1;i<=m;++i) {if (ty[i]!=3) {x= (ty[i]==1?1:0);                for (int j=l[i];j<=r[i];++j) a[j]=x;                } else for (int j=l[i];j<=r[i];++j) a[j]^=1;                        if (L[i]<=id && id<=r[i]) {for (; L[i]<=r[i];++l[i])                            if (!a[l[i]]) {id=l[i];                        Break            }} printf ("%d\n", id); }} else            while (m--) puts ("1");    Fclose (stdin), fclose (stdout); return 0;}
T2

/* Divided into two people like, only a like, only b like * and then enumerate from the two people like to choose K the cheapest * and then greedy to choose the rest of the * * * * Bulk example run out.    */#include <cstdio> #include <algorithm>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=2e5+1;int n,m,k,a[n],b[n],v[n],both[n];/*int aaa,bbb;void dfs (int now,int step,int aa,int bb) {if (aa>k | |    BB&GT;K) return;        if (step==m) {if (aa==k && bb==k) ++ans;    return;        } if (Aaa==now) {++aaa;            if (Bbb==now) {++bbb;            DFS (NOW+1,STEP+1,AA+1,BB+1);            DFS (NOW+1,STEP,AA,BB);        --BBB;            } else {DFS (NOW+1,STEP+1,AA+1,BB);        DFS (NOW+1,STEP,AA,BB);    }--aaa;            } else if (Bb==now) {++bbb;            DFS (NOW+1,STEP+1,AA,BB+1);       DFS (NOW+1,STEP,AA,BB);     --BBB; }}*/inline BOOL CMP (const int &AMP;X,CONST int &y) {return v[x]<v[y];}    int main () {freopen ("b.in", "R", stdin);    Freopen ("B.out", "w", stdout);    N=read (), M=read (), K=read ();    for (int i=1;i<=n;++i) v[i]=read ();    int aa=read (), BB;    for (int i=1;i<=aa;++i) a[i]=read ();    Bb=read ();    for (int i=1;i<=bb;++i) b[i]=read ();    Std::sort (A+1,A+1+AA);    Std::sort (B+1,B+1+BB);//which two people like int aaa=1,bbb=1,emp=0;        while (Aaa<=aa && bbb<=bb) {if (a[aaa]>b[bbb]) ++bbb;            else if (a[aaa]<b[bbb]) ++aaa;                else {BOTH[++EMP]=A[AAA];            ++AAA,++BBB;    }}/* for (int i=1;i<=emp;++i) printf ("%d", Both[i]); *///Std::sort (BOTH+1,BOTH+1+EMP,CMP);    Long Long ans=0;        for (int i=1;i<=k;++i) ans+=v[both[i]];        if (emp>k) {//First of all like to lose m-=k;    k=0; } else {m-=emp;    K-=emp;        }//judge if the remainder is enough if (m< (k<<1)) {printf ("-1");        Fclose (stdin); fclose (stdout);    return 0;    } int cnt=1;emp=0;        for (int i=1;i<=aa;++i) {if (a[i]!=both[cnt]) a[++emp]=a[i];    else ++cnt;    } aa=emp;    Cnt=1,emp=0;        for (int i=1;i<=bb;++i) {if (b[i]!=both[cnt]) b[++emp]=b[i];    else ++cnt;    } bb=emp;        if (K>aa | | k>bb) {printf ("-1");        Fclose (stdin); fclose (stdout);    return 0;    }/* for (int i=1;i<=aa;++i) printf ("%d", a[i]);    Puts ("");    for (int i=1;i<=bb;++i) printf ("%d", b[i]); */Std::sort (A+1,A+1+AA,CMP);    Std::sort (B+1,B+1+BB,CMP);//Then greedy to select the remaining for (int i=1;i<=k;++i) ans+=v[a[i]]+v[b[i];    int i=k+1,j=k+1;        while (i+j<m) {if (V[a[i]]>v[b[j]]) ans+=v[b[j++]];    else ans+=v[a[i++]];        } printf ("%lld", ans);    Fclose (stdin); fclose (stdout);return 0;} 
T3


#include <cstdio> #include <iostream> #include <fstream> #include <cmath> #include <cstring > #include <algorithm>using namespace std; #define SET (a) memset (A,0,sizeof (a)) #define F (I,A,B) for (int i=a;i <=b;++i) #define UF (I,A,B) for (int. i=a;i>=b;--i) #define OPENF (a) freopen (#a ". In", "R", stdin); Freopen (#a ". Out", " W ", stdout) typedef long long ll;typedef long long ll;typedef unsigned long long ull;typedef unsigned long long ull;const in T maxn=400+10;const int maxm=5e4+10;ll n,m;ll u[maxm],v[maxm];bool used[maxn],a[maxn][maxn];ll f[maxn],xx;ll tt;void    Check () {xx=0;    Set (f);    F (I,1,n) if (!used[i]) f[++xx]=i; F (i,1,xx) f (j,1,i) if (F[i]!=f[j]&&!a[f[i]][f[j]]) {a[f[i]][f[j]]=1;++tt;}}    void Dfs (int step) {if (step==m+1) check ();    ll U1=u[step],v1=v[step];    if (!used[u1]&&!used[v1]) {Used[u1]=1;dfs (step+1); Used[u1]=0;used[v1]=1;dfs (step+1); used[v1]=0;}    if (Used[u1]&&!used[v1]) {Used[v1]=1;dfs (step+1); used[v1]=0;} if (!used[u1]&& Used[v1]) {Used[u1]=1;dfs (step+1); used[u1]=0;}    if (used[u1]&& used[v1]) DFS (step+1); return;}    int main () {OPENF (c);    scanf ("%d%d", &n,&m);    F (i,1,m) scanf ("%d%d", &u[i],&v[i]);    Set (used);    Set (a);    DFS (1);    printf ("%lld", TT); return 0;}
Positive solutions and Code T1

Discrete segment Tree

For each interval, maintain a \ (tag\), maintaining the leftmost \ ( 0\) and leftmost \ (1\) position

Then the \ (1\) operation is to change the interval's \ (tag\) to the interval left endpoint

Then consider marking the next pass

\ (1\) operation \ (+\) any action or \ (1\) operation

\ (2\) operation \ (+\) any action or \ (2\) operation

\ (3\) operation \ (+1\) operation becomes \ (2\) operation

\ (3\) operation \ (+2\) operation becomes \ (1\) operation

\ (3\) operation \ (+3\) operation becomes no action

Then the direct discretization + line tree will be OK, do not need to open the point of dynamic

T2

Put all the items into: Two people like,\ (a\) like,\ (b\) like, do not like the

Enumeration of the items that both people like to choose how many (assuming that \ (x\)), then in \ (a\) favorite items and \ (b\) like the O ' clock at least ( k-x\) (with a greedy thinking , it is obvious to choose the right value before \ (k-x\) the small ones), and then if you have not chosen enough \ (m\) , in the two people do not like the least of those items to meet the conditions

So from small to large enumeration \ (x\), keep summing on the line

T3

For this question, consider a more general question: Suppose \ (f_k (S) =f_{k-1} (S\cup \{v_i\}) represents \ (k\) when an individual comes over,\ (s\) The probability that the apples within the set are still alive is \ (\gt 0\), the discussion gets three kinds of cases

    • \ (u_k,v_k\) is in \ (s\) , then \ (F_k (S) =0\)(the two must eat at least one, so the \ (s\) set of apples can not be left)
    • \ (u_k,v_k\) has one in \ (s\ ), assuming \ ( u_k\) in \ ( s\) , then \ (F_k (S) =f_{k-1} (s\ Cup \{v_i\}) \)
    • \ (u_k,v_k\) is not in \ (s\) , then \ (F_k (s) =f_{k-1} (s) \)

So now all of the \ (F_m (\{p\}) =1\) are found, by the way (g (P) \) is from \ (F_m (\{p\}) \) run the above algorithm to get the final set

The observed \ ((u,v) \) legal condition is \ (F_m (\{u\}) =1,f_m (\{v\}) =1,g (U) \cap g (v) =\varnothing\)

Direct enumeration to get answers

Afternoon lectures: Examples of trees 1

Given a tree \ (n\) node, you can perform a \ (n?1\) operation, each of the following steps:

    • Select \ (u,v\) two nodes with a degree of \ (1\) .
    • Add the distance between \ (u,v\) to \ (ans\) .
    • Remove \ (u\) from the tree.

Ask for an action sequence that makes \ (ans\) the largest.

Solution:

First, the diameter is taken out, a point outside the diameter of a one and a certain end of the diameter pair and delete, and finally the diameter is deleted.

Prove:

If there is no point outside the current diameter, then it is obvious that the end of the diameter can only be deleted, otherwise the end of the diameter must not be deleted.
Because the first to delete a diameter outside the point and then delete the diameter of the end point must be not inferior to the first cut the diameter of the endpoint and then delete the diameter outside the points.

For example, there are three points \ (x,y,z\),\ (x,z\) is the two ends of the tree diameter,

Assuming that the delete order is \ (x,y\), then \ (ans+=dis[x][z]+dis[y][z]\)

Assuming that the delete order is \ (y,x\), then \ (Ans+=\max (dis[x][y],dis[y][z)) +dis[x][z]\)

Example 2

Given a \ (n\) point \ (m\) edge of the weighted non-connected map,\ (q\) inquiry, each query \ (u_i\) to \ (v_i\) the shortest path length

\ (N,q\le 10^5,m-n\le 20\)

Solution:

Notice \ (m-n\le 20\), then this picture is actually a tree more than a handful of non-tree side

Start with a build tree, then there will be several sides not on this spanning tree, marking points that have non-tree-side connections

Then the marked point of the most \ (40\) , first run \ (40\) single source The shortest circuit to find out these marked points to all the remaining points of the shortest

For a query, if the shortest path (run \ (lca\) is only passed through the edge of the spanning tree, then it is calculated directly; if you pass the marked point, you can see if the non-tree edge of the connection will affect the answer, try updating.

Example 3

Given a tree of \ (n\) nodes, the definition of the leaf is a node of degrees (1\) , and the point set \ (s\) is good if the distance between the points in any two \ (s\) is met \ (\le k\ , it is now required to divide all the leaves into a few good sets of disjoint, and at least how many good sets.

\ (N,k\le 10^6\)

Solution:

The lecturer said that such topics are generally greedy, I do not know what kind of topic ... (What sort of topics are there in the tree Orz)

Choose a root, easy to choose a root that is not a leaf, and then can be greedy from the bottom up.

Set \ (f_p\) indicates that \ (p\) is the number of good collections that have been completed within the subtree of the root,\ (g_p\) represents the distance from the most distant leaves in the incomplete collection ( p\) .

Consider how to calculate \ (f_p\) and \ (g_p\).

First of all the son's \ (f\) first sum, and then all the sons of \ (g\) Sort, check the largest \ (g\) and the second large \ (g\) add is greater than \ (k\) , if it is greater than, then the largest \ (g\) is deleted, and the \ (f_p\) plus \ (1\). Otherwise it makes \ (g_p\) equal to the largest \ (g+1\).

Example 4

Given \ (n\) nodes, there is a number on each node that requires these nodes to construct a binary search tree that satisfies the number on the two nodes adjacent to the edge coprime
\ (N\le 600\)

Solution:
Sort first, so that \ (f[i][j][k]\) means \ (i\) points to span class= "Math inline" >\ (j\) points to \ (k\) for the root is feasible
transfer first check for the existence of \ (u\in [i,k-1]\) satisfies \ (f[i][k-1][u]=1\) and \ (u\) with \ (k\) on the right side of the number coprime
to check for the presence of \ (v\in [k+1,j]\) satisfies \ (f[k+1][j][v]=1\) and \ (v\) and \ (k\) coprime

But this is \ (O (n^4) \) (array is \ (n^3\) , transfer is \ (n\) )
Consider optimization:
Notice that there are some repetitive operations on the above procedure. So set \ (l[i][j]\) indicates whether the presence \ (k\in [i,j]\) satisfies \ (f[i][j][k]=1\) and \ (k\) the number and \ (j+1\) the number on the coprime, similarly defined by \ (r[i][j]\)

Yale-Yale Study 10.5

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.