计蒜客初赛5
来源:互联网 发布:unity3d 绳子插件 编辑:程序博客网 时间:2024/06/14 01:36
开打了计蒜客的比赛,这次题目难度不大,就是有点坑点,拼点细心与手速,最终晋级的题也提到了三题。
一开始,a思路挺顺,就是有点大意,忽略了两个细节,wa了两发,奔着300+就去了,心态有点方
不过b题跑成功后,发现c的数据并没有卡掉我的程序,于是一起拿下,成功晋级
A. UCloud 机房的网络搭建
思路:这就是最基础的贪心,每次选连接数最多的分线器,一个排序,加个判断,impossible的特殊判断即可
最后就是一定要注意特殊值,0主机不用进循环直接输出,单独考虑(WA掉)。然而,到此,一定要冷静,因为1主机其实也不用进循环(再次WA掉)
#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>using namespace std;const int maxn = 110;int a[maxn];bool cmp(const int a,const int b){ return a>b;}int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i<m;i++) { scanf("%d",&a[i]); } if(n==0||n==1) { printf("%d\n",0); continue; } int sum = 1; sort(a,a+m,cmp); int t; for(t=0;t<m;t++) { sum += a[t] - 1; if(sum >= n) { printf("%d\n",t+1); break; } } if(t==m) { printf("Impossible\n"); } } return 0;}
B/C. UCloud 的安全秘钥(简单/中等)
思路:这题由于题目说是以数字出现次数作为评判标准,那么当然以数组记录出现次数,然后遍历一遍数字串进行判断,O(m*(k+n))的时间复杂度,直接过了b和c两题,一开始还有点不太相信,算了几遍时间,确定没问题后,成功晋级
#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>using namespace std;const int maxn = 50010;int s[maxn];int collect[maxn];int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { scanf("%d",&s[i]); } int m; scanf("%d",&m); while(m--) { memset(collect,0,sizeof(collect)); int k; scanf("%d",&k); for(int i=0;i<k;i++) { int temp; scanf("%d",&temp); collect[temp]++; } int wrong = 0; int sum = 0; for(int i=0;i<k;i++) { collect[s[i]]--; if(collect[s[i]]<0) { wrong ++; } } if(wrong == 0) { sum++; } for(int i=0;i<n-k;i++) { collect[s[k+i]]--; if(collect[s[k+i]]<0) { wrong ++; } collect[s[i]]++; if(collect[s[i]]<=0) { wrong--; } if(wrong == 0) { sum++; } } printf("%d\n",sum); } } return 0;}
阅读全文
1 0
- 计蒜客初赛5
- 2017计蒜客初赛5
- 计蒜客初赛4练习题
- 2017计蒜客初赛6
- 初赛复习5
- 计蒜客-2017初赛第一场
- 计蒜客初赛3练习赛
- ACM初赛试题(5)
- 计蒜客2015 初赛题解及代码
- “顶嵌杯”--初赛第5题分析
- 天梯赛初赛 5-4 帅到没朋友
- 爱奇异17/5/14初赛题目
- 计蒜客 初赛 第三场 A题:腾讯手机地图
- 2017 计蒜客初赛 第二场 A 百度的年会游戏
- 2017 计蒜客初赛 阿里天池的新任务(KMP算法)
- 2006 年百度之星程序设计大赛初赛题目 5
- 蓝桥杯 2011年第二届C语言初赛试题(5)
- 百度之星初赛A第5题 BD String
- Output\TEST.sct(7): error: L6236E: No section matches selector
- Hibernate入门07_继承映射02_joined方式
- Python常用标准库(batteries included)
- pe逆向入门笔记一汇编指令学习及crackme初体验
- MySQL索引介绍
- 计蒜客初赛5
- Android启动过程深入解析
- centos7安装ssh服务
- 采药
- DB2 权限
- 在Oracle12c上添加了Scott用户,但是为什么再次进入的时候却显示invalid username/password;logon denied
- 最大上升子序列和
- 使用哈希表解决几个常见算法题
- Linux 信号浅谈