Codeforces #310ACase of Matryoshkas(模拟)
来源:互联网 发布:自动发卡密源码 编辑:程序博客网 时间:2024/05/21 08:36
【题目链接】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));}/*input3 22 1 21 3output1input7 33 1 3 72 2 52 4 6output10input7 33 1 2 72 3 52 4 6output8*/
0 0
- Codeforces #310ACase of Matryoshkas(模拟)
- 【CodeForces 555A】Case of Matryoshkas(模拟)
- C. Case of Matryoshkas( Codeforces Round #310 (Div. 2) 模拟)
- Codeforces 556C Case of Matryoshkas【模拟】
- Codeforces #310 div2 C. Case of Matryoshkas
- Case of Matryoshkas CodeForces
- CF#310-C-Case of Matryoshkas-模拟水题
- [Codeforces Round #310 DIV1A (CF555A)] Case of Matryoshkas
- COdeforces 555 A. Case of Matryoshkas
- CodeForces-556C Case of Matryoshkas
- CodeForces 555A Case of Matryoshkas
- 【35.37%】【codeforces 556C】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_C. Case of Matryoshkas
- A. Case of Matryoshkas
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第五章 循环结构 部分例题&课后题讲解
- 1.struts2初体验
- 从jpanel中调出一个JDialog,并且使得父窗口jpanel的控件不能用
- 静态模式makefile中$(cobjs): $(obj)/%.o: $(src)/%.c
- 预测小孩未来身高小程序
- Codeforces #310ACase of Matryoshkas(模拟)
- ROM、RAM、DRAM、SRAM、SDRAM
- 已备份数据库的磁盘结构版本为611,服务器支持版本为539,无法还原或升级数据库
- xiaopanOS启动及字典
- C++经典面试题(九)
- 【算法】8 图文搭配诠释三种链表及其哨兵
- oracle表空间使用情况
- 期末模拟——数钱是件愉快的事
- JavaScript 创建对象的几种方式