Codeforces #310ACase of Matryoshkas (analog)

Source: Internet
Author: User

" Topic link " click here~~

" The main idea" gives you n toys, the stipulation only small toy sets in the big above, moreover is the specification increments successively, for example: 1->2->3, asks all toy sets to complete the minimum time which needs to spend

" problem-solving ideas ": only blame CF time too late, the day before night, the spirit a bit tired, the first question or after the game to do, hey ~ ~ can only say Taixu ~ ~

My approach: To find the sequence of 1, and then in turn to determine the following

Code:

 #include <bits/stdc++.h>using namespace Std;const int N=1e6;int num[n];int n,m,k,t        , Ans,cnt,res,top;int Pre,last,len;int Main () {while (scanf ("%d%d", &n,&m)!=eof) {int h1=0,res=0;        int Q,o,ans;        BOOL ok=0;            while (m--) {scanf ("%d", &q);                for (int i=1; i<=q; ++i) {scanf ("%d", &num[i]);                if (num[i]==1) {ok=1;                }} if (ok) {h1=1;                    for (int i=2; i<=q; ++i) {if ((num[i]) = = (num[i-1]+1)) h1++;                else break;                } res+=q-h1;            ok=0;            } else {res+=q-1;        }} res+=n-h1;    printf ("%d\n", res); } return 0;} 
a way to see someone else:

The idea is clear, take come to borrow for a moment ~ ~

/*res: Record the longest satisfying condition that is the length of the monotonically increasing sequence (n-m-res+1): Each set of toys assumes the time required to disassemble all (N-res): The time of all toys re-set */#include <bits/stdc++.h>using namespace Std;const int N=1e6;int num[n];int n,m,k,t,ans,cnt,res,top;int pre,last,len;int Main () {    cin>>n >>m;    res=0;    for (int i=0; i<m; ++i)    {        cin>>k;        last=len=0;        for (int i=0; i<k; ++i)        {            cin>>num[i];            if (num[i]==last+1)            {                last++;                len++;            }        }        Res=max (Res,len);    }    printf ("%d\n", (n-m-res+1) + (n-res));} /*INPUT3 1 3output1input7 1 3 6output8*/2 4 6output10input7 1 2 3 4



Codeforces #310ACase of Matryoshkas (analog)

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.