文章目录

  • 题目描述
    • 输入描述
    • 输出描述
    • 输入输出样例
    • 线索提示
  • 一、解题思路
  • 二、题解
    • 源代码
    • VJudge评判结果
  • 参考文献
  • 写在最后

题目描述

Cheat Sheet (小抄)

University of Shanghai for Science and Technology starts a course called Film Appreciation of Black Album recently. To be the best “Blackologist” in the university, Setsuna is actively preparing for the exam.

The examination of the course is open book; that is to say, you can only take one single-sided cheat sheet to the exam. The cheat sheet can write n characters at most.

Setsuna has m keywords that she wants to write on the cheat sheet. Her memory is not very good, so there may be some duplicate keywords. Each keyword consists of several visible characters(visible characters refer to characters with ASCII code between 33 and 126 inclusive).

For both readability and neatness, keywords written on the cheat sheet should be separated by at least one space and must be different from each other.

Setsuna wants to know how many distinct keywords she can write down on the cheat sheet at most.

Uppercase and lowercase letters are considered different characters.


输入描述

The first line contains two integers n,m(1≤n,m≤1000).

The second line contains m keywords separated by exactly one space. The length of each keyword is no more than 100. It is guaranteed that keyword only consists of visible characters.


输出描述

Output one integer indicating the answer.


输入输出样例

//Example 1
//Input
40 5
myworld lusto KR12138 oneman233 SetsunaQAQ//Output
4
//Example 2
//Input
7 2
^_^ ^_^//Output
1

线索提示

In sample 1, it takes 42 characters to write all the words down. So Setsuna can write down at most four.

In sample 2, there is only one keyword.


一、解题思路

上面说了一大堆,翻译过来的人话就是:

现在我们的主人公要做小抄,但是小抄不能无限长最多为n,有长度限定,但是我们的主人公又要有m个字要写。题目中有以下几点是值得注意的。

  • 第一行的输入包含两个整数n,m(1≤n,m≤1000),分别代表小抄的最大限制字符数和我们亲爱的主人公想要抄上去的字符个数;
  • 题目中要求我们抄上去的单词不能重复
  • 要求我们抄上去的单词的个数越多越好
  • 但是抄上去的单词个数不能超过所给的最大长度n(包含空格)

对于上述的要求我们可以得到对应的解题步骤

  1. 不能重复 : 使用STL标准库中的set来进行筛选,将每一个字符String存进set中;
  2. 越多越好 : 创建一个int数组,统计set中每一个string的字符的个数,接着对int数组进行排序;
  3. 最大长度 : 遍历一遍上一步中创建的int数组,计算最大字符数和字符长度。

二、题解

源代码

代码如下:

/*
* Author:   FeverTwice
* Date:     2021-05-02
* Func:     Solution for Cheat Sheet
*/#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <functional>
#include <set>#define debug(a) cout<<#a<<"="<<a<<endl;
#define lyh(i,a,b) for(int i=a;i<=b;i++)
#define hyl(i,a,b) for(int i=a;i>=b;i--)
#define LL long long
#define mm memset
#define EPS 1e-8
#define INF 0x7fffffff
using namespace std;set<string> sestr;            //创建具有自动去重的集合setstrint main()
{int cnt = 0, res = 0, len = 0;  //cnt:创建字典后的元素个数,res:最大小抄数,len:总长度int l[1020] = {};      //记录字典内元素的长度int n, m;cin >> n >> m;string str;for (int i = 0; i < m; i++){cin >> str;sestr.insert(str);}for (auto iter : sestr){//迭代器迭代统计对应的字符个数l[cnt++] = iter.size();}sort(l, l + cnt);           //排序,得到字符长度for (int i = 0; i < cnt; i++){if (len + l[i] <= n){res++;                //字符个数加一len += (l[i] + 1);   //+1是为了模拟加上后面的空格}}cout << res << endl;return 0;
}

VJudge评判结果


参考文献

[1]2020 年 “联想杯”全国高校程序设计在线邀请赛暨第三届上海理工大学程序设计竞赛C. Cheat Sheet, Author : 容艾假


写在最后

各位看官,都看到这里了,麻烦动动手指头给博主来个点赞8,您的支持作者最大的创作动力哟! <(^-^)>
才疏学浅,若有纰漏,恳请斧正
本文章仅用于各位同志作为学习交流之用,不作任何商业用途,若涉及版权问题请速与作者联系,望悉知

Cheat Sheet (小抄) Visual Judge (Set3)相关推荐

  1. Olympiad (奥林匹克信息赛) Visual Judge (Set3)

    文章目录 题目描述 输入描述 输出描述 输入输出样例 线索提示 一.解题思路 二.题解 源代码 VJudge评判结果 写在最后 题目描述 The recent All-Berland Olympiad ...

  2. linux cheat,一个cheat命令 == Linux命令小抄大全

    一个cheat命令 == Linux命令小抄大全 2014-12-06                                cricode                           ...

  3. 程序员小抄 (转载自酷壳,一个专注技术的博客)

    你是否会经常忘记一些CSS中的函数名或是一些属性名,那个时候,你一定觉得,如果手边有一个"小抄"(Cheat Sheet)就好了.当然,这个"小抄"不是给你作弊 ...

  4. Cheat Sheet的意思

    刚才查了下:Cheat  Sheet的意思是备忘录. cheat是作弊的意思.这个词组原来的意思应该是考试作弊用的小抄吧.

  5. 这份 python 在线小抄,要多全有多全!

    今天给大家分享老曾制作的Python cheat sheet,直接看图⬇️ 小抄资料获取 关注左侧[python自留地] 回复 20002 对于刚刚学习或者不经常用Python的人来说,对编程语言的细 ...

  6. 这份 Matplotlib 使用小抄,要多全有多全

    今天给大家分享一位GitHub大神制作的Matplotlib cheat sheet,直接看图⬇️ 那么我们来看看这张图里到底藏了哪些宝贝. 01 图形类型 02 图例配置 03 颜色选项 04 线条 ...

  7. 快来看这份 Matplotlib 使用小抄,不全找我

    今天给大家分享一位GitHub大神制作的Matplotlib cheat sheet,直接看图⬇️ 相关文件 小伙伴们可以关注小编的Python源码.问题解答&学习交流群:733089476 ...

  8. 机器学习入门必备的13张“小抄”(附下载)

    目录 1)TensorFlow 2)Keras 3)Neural Networks 4)Numpy 5)Scipy 6)Pandas 7)Scikit-learn 8)Matplotlib 9)Pyt ...

  9. Git Cheat Sheet 中文版

    Git Cheat Sheet 中文版 本文内容转载GitHub repo Git-Cheat-Sheet 索引 配置 配置文件 创建 本地修改 搜索 提交历史 分支与标签 更新与发布 合并与重置 撤 ...

最新文章

  1. iphonex如何关机_iPhone X手机屏幕出现绿线怎么回事_屏幕绿线该如何处理?
  2. 30个极大提高开发效率的Visual Studio Code插件
  3. swoole 1.79 websocket 聊天室 基于swoole_server
  4. python如何实现通知_ExASIC: 用python实现一个通知机器人
  5. poj 3280(简单区间dp)
  6. 多组测试数据求最大值
  7. sql server try...catch使用
  8. JavaWeb前端:HTML5 简介
  9. jmeter+ant+jenkins的自动化接口测试
  10. C语言里printf函数格式控制符的完整格式
  11. android解压sd卡中的压缩文件
  12. 计算机软件编程英语词汇集锦一
  13. win10彻底关闭自动更新
  14. 利用NEO与Unity制作游戏(第2部分)
  15. File 和 InputStream, OutputStream 的用法
  16. 【Linux】从冯诺依曼体系到初识Linux下的进程
  17. java系统开发注意事项
  18. VS2017 无法启动 IIS EXPRESS Web 服务器。 工作进程未能正确初始化,因而无法启动。返回的数据为错误信息。已解决!!!
  19. android activity pause,关于android:onPause()和onStop()在Activity中
  20. Series(一):Series的创建方式和常用属性说明

热门文章

  1. Elasticsearch工作原理
  2. 时间戳是从什么时候开始的?
  3. 肠·道 | 7月14日,9位专家北京录制,开放140位现场观众!
  4. [毕业论文][格式修改][摘要修改]毕业论文格式内容修改小技巧
  5. 谁是三国演义里最奸诈的人
  6. Kali linux查看局域网内其他用户的输入信息
  7. MySQL Select Distinct什么意思
  8. 程序员的奋斗史(三十八)——大学断代史(二)——我与数据库的故事
  9. 深度学习应用篇-计算机视觉-语义分割综述[5]:FCN、SegNet、Deeplab等分割算法、常用二维三维半立体数据集汇总、前景展望等
  10. Java后端下载EXCEL模板