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 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...
随机推荐
- POJ 3688 Cheat in the Game(博弈论)
[题目链接] http://poj.org/problem?id=3688 [题目大意] 有俩人玩一个取石子的游戏,你是裁判. 游戏中有W块石头和N张卡片,卡片上分别写着数字Ai. 玩家随机抽走一张卡 ...
- [CF819B]Mister B and PR Shifts
题意:定义一个排列$p_{1\cdots n}$的“偏移量”$D=\sum _{i=1}^n\left|p_i-i\right|$ 求它所有的轮换排列中偏移量最小的是多少,要求输出轮换序数 暴力就是求 ...
- [BZOJ1559]密码
数据范围特别小,考虑状压DP 因为要求给定的字符串在母串中出现,所以可以用AC自动机辅助DP 因为AC自动机不能处理模式串互相包含的情况,所以先把互相包含的串去掉(暴力就行,数据范围太小) 因为要状压 ...
- 【枚举】【权值分块】bzoj1112 [POI2008]砖块Klo
枚举长度为m的所有段,尝试用中位数更新答案. 所以需要数据结构,支持查询k大,以及大于/小于 k大值 的数的和. 平衡树.权值线段树.权值分块什么的随便呢. #include<cstdio> ...
- freedom isn't free
财务自由(除去房和车) 第一阶段: 个人存款达到50万以上 第二阶段 个人存款100~200万 第三阶段 个人存款400万以上 第三阶段以上才能算实现了相对较好的财务自由!come on , boys ...
- select * from sys.sysprocesses
MSDN:包含正在 SQL Server 实例上运行的进程的相关信息.这些进程可以是客户端进程或系统进程. 视图中主要的字段: 1. Spid:Sql Servr 会话ID 2. Kpid:Windo ...
- S3C2440的存储器映射(27根地址线如何寻找1G的地址)
转:http://blog.csdn.net/ce123_zhouwei/article/details/6882091 查S3C2440的数据手册可知S3C2440可寻址1G的地址范围,但是S3C2 ...
- 自己做的javascript简易计算器
html <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF- ...
- nagios学习记录
这几天开始接触nagios,记录下学习的心得 监控机上需要安装nagios,nagios-plugins, nrpe 被监控机上需要安装nagios-plugins, nrpe nagios通过插件n ...
- Intellij IDEA 2017 破解
http://idea.lanyus.com/ https://www.cnblogs.com/wang1024/p/7485758.html