CodeForces-556C Case of Matryoshkas
来源:互联网 发布:4g网络1g流量能用多久 编辑:程序博客网 时间:2024/05/16 05:30
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 1e5 + 5;int n, k, m, temp;int doll[maxn];int cnt;int main(){ while(~scanf("%d %d", & n, & k)) { cnt = 0; for(int j = 1; j <= k; j ++) { scanf("%d", & m); for(int i = 0; i < m; i ++) scanf("%d", & doll[i]); if(doll[0] == 1) { temp = m; for(int i = 0; i < m; i ++) { if(doll[i] == i + 1) cnt ++; else break; } } } printf("%d\n", ((n - temp) - (k - 1)) + (temp - cnt) + (n - cnt)); } return 0;}
题意:差不多可以转换成:给一个n和k。n代表1,2,4,5,6,7....n序列中的最大数。2代表两条链。之后2行第一个数字代表 这一行链的长度,再输入链(每条链都是升序)。之后有两种操作。第一种是取一条链的末尾数。第二种是将取出的末尾数重新连在其他链上(必须大于原末尾)。问几步操作后,可以整合成一条链。
题解:又是一道数学题..先找到开头是1的链。记录该链的长度temp,之后再记录1,2,3,4....连续的数量cnt。最后那个式子并没有简化,好理解吧。((n - temp) - (k - 1))表示除了含1的那条链,需要拆多少个末尾。(temp - cnt)表示含1的那行除了连续的不拆,其他末尾都拆。(n - cnt)表示将拆了的重新连上的步骤数。各部分全+ 即是总操作步数。
0 0
- CodeForces-556C Case of Matryoshkas
- Codeforces 556C Case of Matryoshkas【模拟】
- 【35.37%】【codeforces 556C】Case of Matryoshkas
- CodeForces 556C Case of Matryoshkas 娃娃组装
- Case of Matryoshkas CodeForces
- Codeforces #310 div2 C. Case of Matryoshkas
- CodeForces 567C Case of Matryoshkas map+递推
- COdeforces 555 A. Case of Matryoshkas
- CodeForces 555A Case of Matryoshkas
- C. Case of Matryoshkas( Codeforces Round #310 (Div. 2) 模拟)
- codeforces_C. Case of Matryoshkas
- A. Case of Matryoshkas
- Codeforces 555A Case of Matryoshkas 套娃娃
- CodeForces 555A Case of Matryoshkas 娃娃组装
- [Codeforces Round #310 DIV1A (CF555A)] Case of Matryoshkas
- 【CodeForces 555A】Case of Matryoshkas(模拟)
- CF#310-C-Case of Matryoshkas-模拟水题
- 【CodeForces555A】Case of Matryoshkas 题解
- Battle City
- HDU 5363-K - Key Set-递推
- 总结一下 matplotlib 画图常用功能
- UI0_带分区的省市区
- Java心得13
- CodeForces-556C Case of Matryoshkas
- Visual Studio远程调试的使用
- 生成素数序列----埃拉托斯特尼筛法
- 关于pymongo两种连接方法MongoClient和Connection连接mongodb的写入效率分析
- 安装Win7ghost 之后,发现鼠标和键盘没有反应,失效
- 单例模式范例
- UI0_cell自适应高度
- UI09_自定义cell
- POJ 1006 Biorhythms (中国剩余定理)