Codeforces Round #310 (Div.1) __codeforces

Source: Internet
Author: User

The mouth contestant is very good, one does not need to hit the code two not to drop rating three can also do chores ....
Feel this set of questions is not difficult, but was the topic of the blind people ...

555A. Case of Matryoshkas

Title: given n n size from 1 1 to N of the set of Eva, initially set into K K Tuo, each time you can choose two operations:
1. Choose a doll that is not in any other set of dolls, and take out the doll inside (ask for a baby in the original package)
2. Choose a no longer any other sets of Eva, will be a set of Eva stuffed in (requirements originally there is no set baby)
Minimum number of operations to combine all sets of dolls

If a set of Eva X initial in the innermost, or meet the size of 1...x−1 1...x-1 in it, then this set of baby can not be opened
Take apart all the dolls that need to be opened and merge

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 100100
using namespace std;
int N,m,k,cnt,ans;
int main ()
{
    int i,j,x,last;
    cin>>n>>k;
    for (i=1;i<=k;i++)
    {
        bool flag=false;
        scanf ("%d", &m);
        for (j=1;j<=m;j++)
        {
            scanf ("%d", &x);
            if (j>1)
                ++ans;
            if (flag&&x==last+1)
                --ans;
            else
                ++cnt,flag=false;
            if (x==1)
                flag=true;
            Last=x
        }
    }
    cout<<ans+cnt-1<<endl;
    return 0;
}

555B. Case of fugitive

Topic: given n N Islands, the I I islands can be expressed in an interval [Li,ri] [L_i,r_i], satisfying for arbitrary 1≤i<n 1\leq I have ri<li+1 R_i
There is now a need to frame a bridge between each of the two adjacent islands, and the length of the bridge needs to be between [Li+1−ri,ri+1−li] [l_{i+1}-r_i,r_{i+1}-l_i]
Given M-m block, ask if you can complete the task

The problem can be simplified to a given n−1 n-1 interval and M m points to ask if there is a match that satisfies each point in the corresponding range and all the intervals are matched.

Sort the interval by the left endpoint from large to small, scanning sequentially
Every time you scan to an interval, all points greater than or equal to the left endpoint of the interval are thrown into the set, and then the largest of all points that are less than or equal to the right endpoint of the interval is removed, and no solution exists.

#include <set> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm&
Gt
#define M 200200 using namespace std;
    struct interval{long long l,r,id;
    BOOL operator < (const Interval &i) Const {return L < I.L;
}}intervals[m];
int n,m,ans[m];
set< Pair<long long,int> > s; 
Pair<long long,int> Points[m];
    int main () {int i,j;
    Long Long _l,_r,l,r;
    cin>>n>>m>>_l>>_r;n--;
        for (i=1;i<=n;i++) {scanf ("%i64d%i64d", &l,&r);
        Intervals[i].l=l-_r;
        intervals[i].r=r-_l;
        Intervals[i].id=i;
    _l=l;_r=r;
        for (i=1;i<=m;i++) {scanf ("%i64d", &points[i].first);
    Points[i].second=i;
    Sort (intervals+1,intervals+n+1);
    Sort (points+1,points+m+1);
      for (j=m,i=n;i;i--) {for (; j&&points[j].first>=intervals[i].l;j--) S.insert (Points[j]);  set< pair<long long,int> >::iterator it=s.upper_bound (Make_pair (intervals[i].r+1,0));
        if (It==s.begin ()) return puts ("No"), 0;
    --it;ans[intervals[i].id]=it->second;s.erase (IT);
    } puts ("Yes"); for (i=1;i<=n;i++) printf ("%d%c", ans[i],i==n?)
    \ n ': ');
return 0; }

555C. Case of chocolate

Title: Given a n∗n n*n chocolate, the initial bite off the lower right side of the diagonal line, and then select a position on the vice diagonal, and then select a direction (up/left), all the way to gnaw down, until chewing to an empty position, the output gnaw off the length of

Each bite will divide the current gnawing block into up to two small pieces
Each of the remaining chocolates can be used in a four-tuple group (l,r,left_bound,up_bound

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.