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