题目传送门

 /*
题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步
贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0),先从1开始找到已经套好的娃娃层数,
其他是2次操作,还要减去k-1个娃娃是只要套上就可以
详细解释:http://blog.csdn.net/firstlucker/article/details/46671251
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN]; int main(void) //Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
{
// freopen ("C.in", "r", stdin); int n, k;
while (scanf ("%d%d", &n, &k) == )
{
int cnt = ;
for (int i=; i<=k; ++i)
{
int m; scanf ("%d", &m); int p = ;
for (int j=; j<=m; ++j)
{
scanf ("%d", &a[j]); if (a[j] == ) p = j;
}
if (p)
{
for (int j=p+; j<=m; ++j)
{
if (a[j] == a[j-] + ) cnt++;
else break;
}
}
}
printf ("%d\n", (n - - cnt) * - (k - ));
} return ;
}

贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas的更多相关文章

  1. Codeforces Round #310 (Div. 1) A. Case of Matryoshkas 水题

    C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  2. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  3. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  4. Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题

    B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  5. Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  6. Codeforces Round #310 (Div. 1) C. Case of Chocolate set

    C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...

  7. Codeforces Round #310 (Div. 1) B. Case of Fugitive set

    B. Case of Fugitive Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/p ...

  8. Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)

    题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...

  9. Codeforces Round #310 (Div. 1) B. Case of Fugitive(set二分)

    B. Case of Fugitive time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 我和 HelloGitHub

    我? 我是一个本科学历.无大厂经历,普通的 Python 程序员. 虽然是计算机专业,但是大学玩了四年(Dota)后,发现自己无一技能傍身,要饿死啦!偶然间接触了 Python 这门编程语言,发现编程 ...

  2. 纠结的链接——ln、ln -s、fs.symlink、require

    纠结的链接--ln.ln -s.fs.symlink.require 提交 我的留言 加载中 已留言 inode 我们首先来看看 linux 系统里面的一个重要概念:inode. 我们知道,文件存储在 ...

  3. 让你的 EditText 所有清除

    原文地址:让你的 EditText 所有清除 參考原文:Giving your Edit Texts the All Clear 项目地址(欢迎 Star):ClearEditText 在输入文本的时 ...

  4. Android网络编程之使用HTTP訪问网络资源

    使用HTTP訪问网络资源 前面介绍了 URLConnection己经能够很方便地与指定网站交换信息,URLConnection另一个子类:HttpURLConnection,HttpURLConnec ...

  5. Ubuntu16.04下安装Tensorflow GPU版本(图文详解)

    不多说,直接上干货! 推荐 全网最详细的基于Ubuntu14.04/16.04 + Anaconda2 / Anaconda3 + Python2.7/3.4/3.5/3.6安装Tensorflow详 ...

  6. break return continue

    1.return 语句的作用 (1) return 从当前的方法中退出,返回到该调用的方法的语句处,继续执行 (2) return 返回一个值给调用该方法的语句,返回值的数据类型必须与方法的声明中的返 ...

  7. MSMQ消息队列的安装、启用

    最近研究消息队列,先从微软自带的MSMQ开始,百度如何安装,方式如下: 控制面板---程序和功能--启用和关闭windows功能--Microsoft Message Queue(MSMQ)服务器 默 ...

  8. QmlWinExtras

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/zhengtianzuo06/article/details/78404961QtWinExtras是 ...

  9. Spring Security调研记录【七】--核心模型与实现

    网上有非常多关于Spring Security文章中,都觉得Spring Security(相对于shiro)过于复杂,个人觉得复杂的是Spring Security的官方文档而不是Spring Se ...

  10. javaScript改变HTML

    改变HTML输出流: 在JavaScript中,document.write() 可用于直接向HTML输出流写内容 <!DOCTYPE html> <html> <bod ...