Greedy/thinking questions codeforces Round #310 (Div. 2) c. Case of Matryoshkas

Source: Internet
Author: User

Topic Portal

1 /*2 Test Instructions: Set of dolls, can set a single doll, or the last doll out, finally make 0-1-2-...-(n-1), ask at least a few steps3 Greedy/thinking: Doll Status: Remove + set ON (2), set on (1), set on (0), starting from 1 to find the already set of doll layer,4 The other is 2 operations, but also minus k-1 a doll is just set on it can5 Detailed Explanation:http://blog.csdn.net/firstlucker/article/details/466712516 */7#include <cstdio>8#include <algorithm>9#include <cstring>Ten#include <cmath> One using namespacestd; A  - Const intMAXN = 1e5 +Ten; - Const intINF =0x3f3f3f3f; the intA[MAXN]; -  - intMainvoid)//codeforces Round #310 (Div. 2) C. Case of Matryoshkas - { +     //freopen ("c.in", "R", stdin); -  +     intN, K; A      while(SCANF ("%d%d", &n, &k) = =2) at     { -         intCNT =0; -          for(intI=1; i<=k; ++i) -         { -             intM scanf ("%d", &m);intp =0; -              for(intj=1; j<=m; ++j) in             { -scanf ("%d", &a[j]);if(A[j] = =1) p =J; to             } +             if(P) -             { the                  for(intj=p+1; j<=m; ++j) *                 { $                     if(A[j] = = a[j-1] +1) cnt++;Panax Notoginseng                     Else     Break; -                 } the             } +         } Aprintf ("%d\n", (N-1-CNT) *2-(K-1)); the     } +  -     return 0; $}

Greedy/thinking questions codeforces Round #310 (Div. 2) c. Case of Matryoshkas

Related Article

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.