Cf 101 div.2

Source: Internet
Author: User

Question

Match all the characters and their occurrences.


Question B

Push rules, pay attention to details, such as the midline or something.


Question C

Good questions.

Given n <= 3000 people, queuing, and the number of people whose names are strictly higher than each other num [I], you are required to output their heights (the heights are randomly specified, but it must satisfy the number of people whose names are strictly higher than each other ).

My practices:

After the number of input values is sorted in ascending order, the first value must be: num [1] = 0; otherwise,-1 is output;

The height of all (including the first person) num [I] is 5000,

For example, num [] = {-, 5 ...};

Starting from 5000 5000 5000

Then for num [4] = 2, I find the (2 + 1) position in the constructed sequence, and take the minimum value of [1, 2] val = 5000, assign a val-1 to 4th people.

= 5000 5000 4999 5000

Then num [5] = 2,

==> 5000 5000 4999 4999 5000

Then num [6] = 3,

==> 5000 5000 4999 4998 4999 5000

And so on... This ensures that the number of new inserts is smaller than that of the next one, so it will not affect the people behind.


Question d

Look at the problem, and read other people's code.

[0, l] n hurdles on the runway,NAndL(0 bytes ≤ bytesNLimit ≤ limit 105, 1 hour ≤ hourLLimit ≤ limit 109 ).

Then there are N groups of data:XI,DI,TI,PI(0 bytes ≤ bytesXILimit ≤ limitL, 1 limit ≤ limitDI, Bytes,TI, Bytes,PILimit ≤ limit 109,XIRegion + RegionDILimit ≤ limitL).

Xi is the coordinate. The person must start preparing for the hurdle from Xi-Pi, jump at Xi, and then jump to Di. The leap time is Ti, the time on the ground is a unit distance of 1 s. Must be
Returns the positive direction of the X axis.


The algorithm is:

1. Graph creation:

Xi-pi
To Xi + DI, weight: PI + Ti;

All vertex sets are sorted in ascending order by coordinates, and edge is created for each adjacent vertex.
At the same time, remember to create an inverse edge. (There must be a back edge, which is worth thinking about, because we can use a good hurdle (short leap time, long distance) to reverse run (short time) .)

Dijkstra + set.

Map processes input data, and the ing code is also very good.

Code:

/*Feb 3, 2012 5:54:16 PM yimao D-Take-off Ramps GNU C++ Accepted 530ms 23800KB*/#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <set>#include <map>using namespace std;#define MM(a,b) memset(a,b,sizeof(a));typedef unsigned long long u64;typedef long long lld;const int maxint= 2000000000;#define maxn 200100int n,L,top;struct Edge{    int u,v,w,id;    Edge *next;}*adj[maxn], edge[maxn*3];void Add_edge(int u,int v,int w,int id){    Edge *ptr= &edge[++top];    ptr->u= u; ptr->v= v; ptr->w= w;    ptr->id= id;    ptr->next= adj[u];    adj[u]= ptr;}int cnt;map<int,int>mm;int dis[maxn],Index[maxn],pre[maxn];bool use[maxn];struct cmp{    bool operator()(int i,int j)const{        return dis[i]<dis[j] || (dis[i]==dis[j]&&i<j);    }};set<int,cmp>Q;void Dijkstra(int st,int N){    for(int i=1;i<=N;++i) dis[i]= maxint, use[i]=0;    dis[st]=0;    if( !Q.empty() ) Q.clear();    Q.insert( st );    while( !Q.empty() ){        int u= *Q.begin();        Q.erase(u);        use[u]= 1;        if( u==2 ) return; // L-->2,improve speed;        for( Edge *ptr= adj[u]; ptr; ptr= ptr->next ){            int v= ptr->v;            if( use[v]==0 && dis[v]>dis[u]+ ptr->w ){                Q.erase( v );                dis[v]= dis[u]+ ptr->w;                Q.insert( v );                pre[v]= u;                Index[v]= ptr->id;            }        }    }}int node[maxn];int main(){    //freopen("D.txt","r",stdin);    int i,x,d,t,p;    while(cin>>n>>L){        top=0;        MM( adj, 0 );        cnt=0;        if( !mm.empty() ) mm.clear();        mm[0]= ++cnt, mm[L]= ++cnt;        for(i=1;i<=n;++i){            scanf("%d%d%d%d",&x,&d,&t,&p);            if( x-p<0 ) continue;            if( mm.find(x-p)==mm.end() )                mm[x-p]= ++cnt;            if( mm.find(x+d)==mm.end() )                mm[x+d]= ++cnt;            Add_edge( mm[x-p], mm[x+d], p+t, i );        }        map<int,int>::iterator it1,it2;        for(it1= mm.begin();;++it1){            it2= it1;            if( (++it2)==mm.end() ) break;            Add_edge( it1->second, it2->second, it2->first - it1->first, 0 );            Add_edge( it2->second, it1->second, it2->first - it1->first, 0 ); //////        }        Dijkstra(1,cnt);        printf("%d\n", dis[2]);        int u= 2, c=0;        while(u!=1){            if( Index[u]!=0 ) node[++c]= Index[u];            u= pre[u];            //printf("%d ",u);        }        printf("%d\n",c);        for(i=c;i>0;--i){            printf("%d%c",node[i], i==1 ? '\n' : ' ');        }    }}

Question E

Shen Wen. In fact, it is a question to check whether the classical algorithms are fully understood. It will be done under the guidance of Dal.

It is required to construct a spanning tree. The Edge attributes include S and M, and the edge attributes must be half.

Ideas:
In the prim algorithm, each time an edge with the minimum weight is obtained that connects the vertex set of the St and the non-ST, the attribute must be transformed here. For example, for a vertex that is not a set, if there is a vertex that has the s edge to the st and has m edge at the same time, the priority is given. Otherwise, take S, m at will.

The code is worth thinking about.



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.