Codeforces #310ACase of Matryoshkas(模拟)
【题目链接】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(模拟)的更多相关文章
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...
- Codeforces 691C. Exponential notation 模拟题
C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
- Codeforces 658A. Robbers' watch 模拟
A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces 438D (今日gg模拟第二题) | 线段树 考察时间复杂度的计算 -_-|||
Codeforces 438D The Child and Sequence 给出一个序列,进行如下三种操作: 区间求和 区间每个数模x 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...
随机推荐
- 在WPF中合并两个ObservableCollection
WPF中的ObservableCollection是一个非常常用的集合对象,我们可以通过将它绑定到ListBox之类的集合控件上时,当集合发生变更时,会同步更新到界面上.但是,有的时候我们需要合并两个 ...
- Oracle查询库中记录数大于2千万的所有表
Oracle查询库中记录数大于2千万的所有表 假如当前用户拥有select any table权限,则可以使用下列sql语句: select table_name, num_rows from dba ...
- 正则表达式之 /^(\d)$/
^(\d)$就是0-9的任意一个数字, ^表示以...开头,\d表示0-9的数字,$表示以...结尾,
- 监控Coherence成员的加入和离开集群事件
对server事件的监控主要是实现MemberListener类,对Cache事件的监控主要通过MapListener 参考代码 package coherencetest; import com.t ...
- 定期访问WebLogic Server返回状态的脚本
在运维过程中,经常要获悉WebLogic Server的状态以便于主动的维护,本文通过weblogic WLST脚本初步设计了一下 脚本大概为2个,一是WLST的py脚本,getStates.py c ...
- GyoiThon:基于机器学习的渗透测试工具
简介 GyoiThon是一款基于机器学习的渗透测试工具. GyoiThon根据学习数据识别安装在Web服务器上的软件(操作系统,中间件,框架,CMS等).之后,GyoiThon为已识别的软件执行有效的 ...
- centos搭建git服务器(转)
一:git服务安装 1.安装git相关组件 [root@gitserver ~] yum -y install git 2.创建git用户 [root@gitserver ~] groupadd gi ...
- 多重采样(MultiSample)下的FBO反锯齿 【转】
在三维渲染的过程中,锯齿总是让人讨厌的东西.抗锯齿的一种采用方式是多重采样,本文主要小记一下FBO与多重采样的关系.——ZwqXin.com 首先,关于FBO(Frame Buffer Object) ...
- Java笔记3:Eclipse添加jar包
本文以jedis包为例,演示Eclipse如何添加和使用jar包. 1 建立一个名为ImportJarDemo的JavaProject.在该工程下建立一个libs的文件夹. 2 将下载的jedis ...
- Netty4详解三:Netty架构设计(转)
http://blog.csdn.net/suifeng3051/article/details/28861883?utm_source=tuicool&utm_medium=referral ...