2019.10.11 examination report
Schedule:
T1: 1.5h
T2:1h
T3: 0.5h
Examination room ideas:
T1: In the beginning of the segment tree want to do, and then write the tree line bombed, there is a problem on a single point of modification, use violence to do, the time complexity of O (n * q) ,, got fortieth
T2: the beginning wanted to do with Floyd, I found that the data is too large, the change to do with topological sorting
T3: Originally went to get a very minute part, found that very minute part nor write
Answer: The
T1: 50
T2: 64
T3: 0
Topic analysis:
T1: segment tree written on the subject, and that in fact there is no relationship tree line, 3 is the number of operations with a storage array, then each time the operation 1, once the first determination, if less than the operating number, then put this number into a processed value of 3 after a recent operation, if it is equal, then that has been treated, you deal directly with enough time complexity: O (q)
T2: topological sort, data is too large, fFloyd, dij, spfa timed-out, so we want to another method, according to the requirements of the subject, find a longest path, then the FIG must be a directed acyclic graph, (If there is a ring, then the longest route is + ∞). Directed acyclic graph called topology, topological sorting + DP made available. Then a topological sort hit enough + DP
T3: a chain case: when one strand is the maximum value must be one of the two endpoints, a certain minimum value at a certain point. Expect Score: 10 points
Correct answer:
T1:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstring> #include<map> #include<ctype.h> #define int long long int using namespace std; const int the MAXSIZE = 50.00002 million ; // read into the cache size, do not change int bufpos; char buf [the MAXSIZE]; int Read () { // read in an integer type int int Val = 0 ; for (; buf [bufpos] < ' 0 ' || buf [bufpos]> ' . 9 ' ; bufpos ++ ); for (; buf [bufpos]> = ' 0 ' && buf [bufpos] <= ' . 9 ' ; bufpos ++ ) val = val * 10 + buf[bufpos] - '0'; return val; } int a[10000010]; int b[10000010]; int ans; int tag,lazy; signed main() { freopen("segmenttree.in","r",stdin); freopen("segmenttree.out","w",stdout); buf[fread(buf, 1, MAXSIZE, stdin)] = '\0'; bufpos = 0; int n,m; n=read(); m=read(); for(int i=1;i<=m;i++) { int t; t=read(); if(t==1) { int x,y; x=read(); y=read(); if(b[x]<tag) { a[x]=lazy; b [x] = day; } years - = a [x]; to [x] = y; years + = y; } if(t==2) { int x,y; x=read(); y=read(); if(b[x]<tag) { a[x]=lazy; b [x] = day; } to [x] + = y; years + = y; } if(t==3) { int y; y=read(); tag++; lazy=y; years = n * y; } cout<<ans<<endl; } return 0; }
T2:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstring> #include<ctype.h> #include<queue> #define int long long int using namespace std; int n,m; const int the MAXSIZE = 50.00002 million ; // read into the cache size, do not change int bufpos; char buf [the MAXSIZE]; int Read () { // read in an integer type int int Val = 0 ; for (; buf [bufpos] < ' 0 ' || buf [bufpos]> ' . 9 ' ; bufpos ++ ); for (; buf [bufpos]> = ' 0 ' && buf [bufpos] <= ' . 9 ' ; bufpos ++ ) val = val * 10 + buf[bufpos] - '0'; return val; } queue <int> q; int value[1000001]; struct node { int u; int v; int w; int next; }data[1000001]; int head[1000001]; int cnt; int fl[1000001]; void add(int u,int v,int w) { cnt++; data [cnt] .v = v; data[cnt].w=w; data[cnt].next=head[u]; head[u]=cnt; } // Construction Plan signed main() { freopen("lpsa.in","r",stdin); freopen("lpsa.out","w",stdout); buf[fread(buf, 1, MAXSIZE, stdin)] = '\0'; bufpos = 0; n=read(); m=read(); for(int i=1;i<=m;i++) { int u,v,w; u=read(); v=read(); w=read(); add(u,v,w); fl[v]++; } for(int i=1;i<=n;i++) { if(fl[i]==0) { q.push (I); // if the current point is equal to zero, it is queued } } while(!q.empty()) { int x=q.front(); q.pop(); for ( int I = head [X]; I; I = Data [I] .next) // zero degree point from the beginning to find { IF (value [Data [I] .v] <value [X] + Data [I] .W) // had asked longest path, so the distance data [i] .v is the value [data [i] .v] and data [i] .w + value [ x] is the maximum { value[data[i].v]=value[x]+data[i].w; } FL [Data [I] .v] -; // penetration minus one IF (FL [Data [I] .v] == 0 ) // degree is 0 { q.push(data[i].v); } } } int ans=0; for(int i=1;i<=n;i++) { years = max (year value [i]); } cout<<ans<<endl; return 0; }
T3: ignorant force ing. . .