题目链接click here~~

题目大意】给你n个玩具,规定仅仅能小的玩具套在大的上面。并且是规格依次递增的,比方:1->2->3,求全部玩具套完须要的最小时间花费

解题思路】:仅仅能怪CF时间太晚了,本来前一天熬夜,精神有点疲劳。这次第一题还是赛后补做的,哎~~仅仅能说太虚~~

我的做法:找到序列为1 的。然后依次推断后面的

代码:

#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;
}

看到别人的一种做法:

思路比較清晰,拿过来借鉴一下~~

/*
res:记录最长满足条件即单调递增序列的长度
(n-m-res+1):每组玩具如果所有拆解须要的时间
(n-res):所有玩具又一次套上的时间
*/
#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));
}
/*
input
3 2
2 1 2
1 3
output
1
input
7 3
3 1 3 7
2 2 5
2 4 6
output
10
input
7 3
3 1 2 7
2 3 5
2 4 6
output
8
*/

Codeforces #310ACase of Matryoshkas(模拟)的更多相关文章

  1. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  2. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  3. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  4. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  5. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...

  6. Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)

    大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...

  7. Codeforces 691C. Exponential notation 模拟题

    C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...

  8. Codeforces 658A. Robbers' watch 模拟

    A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  9. Codeforces 438D (今日gg模拟第二题) | 线段树 考察时间复杂度的计算 -_-|||

    Codeforces 438D The Child and Sequence 给出一个序列,进行如下三种操作: 区间求和 区间每个数模x 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...

随机推荐

  1. CentOS 安装 Zookeeper 版本任选

    Zookeeper下载地址各种版本自己选择: https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ Zookeeper 3.4.13版本下载地址 ...

  2. [ZOJ3522]Hide and seek

    题意:给一棵带边权的树,多次询问$(x,y,l)$表示如果加一条连接$x$和$y$的长为$l$的边,所有点到$x$和到$y$的最短路减少了多少 先把题目中的图放上来(雾 考虑用lct维护,先把路径提出 ...

  3. 【DFS序】【莫队算法】【权值分块】bzoj1803 Spoj1487 Query on a tree III

    基本等同这个,只是询问的东西不大一样而已. http://www.cnblogs.com/autsky-jadek/p/4159897.html #include<cstdio> #inc ...

  4. (转)关于Unity3D的编辑器崩溃时的线索定位

    今天在Unity3D编辑器中进行功能测试的时候,编辑器突然崩溃了(就是整个窗口突然消失,进程直接结束)之后也没有任何错误报告信息提示.好吧,应该是偶现问题,我侥幸地想,我用的好歹也是正版啊,不应该总出 ...

  5. 自问自答:在VB中如何实现像C++一样printf的功能

    问: 每个整型都转换成5位的字符串,不足的在前面补0.比如:1转换成“00001”,10转换成“00010”.怎么实现? 答: format(1,"00000") from: 百度 ...

  6. Android 架构 3.实现

    以实现最小化可用产品(MVP)的目标,用最简单的方式来搭建架构和实现代码.IDE采用Android Studio,Demo实现的功能为用户注册.登录和展示一个券列表,数据采用我们现有项目的测试数据,接 ...

  7. Python的编码注释# -*- coding:utf-8 -*-

    # -*- coding:utf-8 -*-的主要作用是指定文件编码为utf-8, 因为一般默认的是ASCII码,如果要在文件里面写中文,运行时会出现乱码,加上这句之后会把文件编码强制转换为utf-8 ...

  8. MediaInfo用来分析视频和音频文件的编码和内容信息的超好用工具

    转载:http://blog.csdn.net/ameyume/article/details/6718705 MediaInfo简介 MediaInfo 用来分析视频和音频文件的编码和内容信息. M ...

  9. VUE ---(9)组件——props数据传递

    本篇资料来于官方文档: http://cn.vuejs.org/guide/components.html#Props 本文是在官方文档的基础上,更加细致的说明,代码更多更全. 简单来说,更适合新手阅 ...

  10. 使用x64dbg分析微信聊天函数并实现发信息

    1.引言 我们知道微信现在不光在手机上很常用,在电脑也是非常常用的,尤其是使用微信联系客户和维护群的人,那这个时候每天都会定期发送一些信息,如果人工操作会很累,所以自动化工具是王道,本节就使用x64d ...