Case of Matryoshkas CodeForces
来源:互联网 发布:蜘蛛纸牌算法 编辑:程序博客网 时间:2024/06/04 18:51
题意:俄罗斯套娃娃。你们都懂得。 然后给定n(娃娃个数),m(几组关系),每组关系中第一个数字是num,代表后面有几个娃娃。问最少花多少时间能把娃娃从1~n套好;
思路:对于能从1开始连续的,一定可以不用拆,连着就好了。然后后面统统都要拆,这样时间才会最短
#include <bits/stdc++.h>using namespace std;const int maxn=1e5+500;int a[maxn];int main(void){ int n,m; cin >> n >> m; int ans=0; for(int i=1; i<=m; i++) { int num; scanf("%d",&num); int x,temp; int flag=0; scanf("%d",&x);temp=x; if(x==1) flag=1; for(int j=2; j<=num; j++) { scanf("%d",&x); if(flag==1 && x==temp+1) { temp=x; continue; } if(x==1) { temp=x; flag=1; } else { flag=0;ans++; } } } ans=ans+ans+m-1; cout << ans << endl;}
// 这题在最后2分钟A出来了,妙不可言。
1.学习一定要静下心来,题目要仔细看要求.
2.有诗人的想象,你可以的!
阅读全文
0 0
- Case of Matryoshkas CodeForces
- Codeforces #310 div2 C. Case of Matryoshkas
- COdeforces 555 A. Case of Matryoshkas
- CodeForces-556C Case of Matryoshkas
- CodeForces 555A Case of Matryoshkas
- Codeforces 556C Case of Matryoshkas【模拟】
- 【35.37%】【codeforces 556C】Case of Matryoshkas
- codeforces_C. Case of Matryoshkas
- A. Case of Matryoshkas
- Codeforces 555A Case of Matryoshkas 套娃娃
- CodeForces 556C Case of Matryoshkas 娃娃组装
- CodeForces 567C Case of Matryoshkas map+递推
- CodeForces 555A Case of Matryoshkas 娃娃组装
- [Codeforces Round #310 DIV1A (CF555A)] Case of Matryoshkas
- 【CodeForces 555A】Case of Matryoshkas(模拟)
- 【CodeForces555A】Case of Matryoshkas 题解
- C. Case of Matryoshkas( Codeforces Round #310 (Div. 2) 模拟)
- Codeforces #310ACase of Matryoshkas(模拟)
- Rxjava2.0教程(一)
- jsp-Servlet基础
- Hibernate检索数据的五种方式
- Problem B
- 字符逆序
- Case of Matryoshkas CodeForces
- spring+spring mvc + mybatis + maven 项目框架搭建笔记<一>
- [ACM_SMU_1104]最优矩阵连乘积(区间dp)
- UVA
- 二叉树--求二叉树的高度/销毁一颗二叉树
- Java 网络编程之NioSocket
- 查找算法系列(二):哈希查找
- Servlet中的getServletContext()
- Android Fragment真正的完全解析(下)