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 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...
随机推荐
- UVA GCD - Extreme (II)
discription Given the value of N, you will have to find the value of G. The definition of G is given ...
- 【暴力】洛谷 P2038 NOIP2014提高组 day2 T1 无线网络发射器选址
暴力枚举. #include<cstdio> #include<algorithm> using namespace std; ][],d,n,x,y,z,num,ans=-; ...
- 使用jmatio读写matlab数据文件
/** * Created by hfz on 2016/2/23. */ import com.jmatio.io.*; import com.jmatio.types.MLDouble; impo ...
- 使用urlretrieve下载图片
示例代码: from urllib.request import urlretrieve from urllib.request import urlopen from bs4 import Beau ...
- Solr6 +mmseg4j+IK-Analyzer + SQLserver +DIH 完全配置
如今做任何一个系统都有搜索,而搜索界有著名的三剑客: solr/elasticsearch/sphinx solr/elasticsearch 为同一类的,都是基于lucene开发的产品,本人也早在几 ...
- 设置MySQL数据库名不区分大小写
Linux下的MySQL默认是区分表名大小写的,通过如下设置,可以让MySQL不区分表名大小写: 1.用root登录,修改 /etc/my.cnf: 2.在[mysqld]节点下,加入一行: lowe ...
- MPFIT for python
MPFIT本来用IDL语言写的,后面有人翻译成了C语言版本.再后面鉴于python语言的流行使用,又有人将其用Cython加了python接口,直接可以在python中调用,极大地方便了额们这些经常用 ...
- XPath注入技术综述
一次完整的 XPath 注入攻击应该包括使用特殊构造的查询来提取一个 XML 数据库内的 数据或者信息.作为一门新的技术,XPath 注入在一定程度上和 SQL 注入漏洞有着惊人的相 似之处,通过下面 ...
- Java笔记9:Spring简单Demo
1 下载spring-framework-3.0.5.RELEASE-with-docs.zip和spring-framework-3.0.5.RELEASE-dependencies.zip,放 ...
- mycat读写分离与主从切换
1, 分库分表的优缺点.以及为什么分表方式无法成为主流? 分表:在台server上,长处是易维护,相似表分区.缺点是在一台dbserver上.无法分担IO.负载集中. 分库:在多台server上,长处 ...