Problem:
Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’!

To compose a story, Stephen wrote out n words consisting of the first 5 lowercase letters of the Latin alphabet. He wants to select the maximum number of words to make an interesting story.

Let a story be a sequence of words that are not necessarily different. A story is called interesting if there exists a letter which occurs among all words of the story more times than all other letters together.

For example, the story consisting of three words “bac”, “aaada”, “e” is interesting (the letter ‘a’ occurs 5 times, all other letters occur 4 times in total). But the story consisting of two words “aba”, “abcde” is not (no such letter that it occurs more than all other letters in total).

You are given a sequence of n words consisting of letters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’. Your task is to choose the maximum number of them to make an interesting story. If there’s no way to make a non-empty story, output 0.

Input
The first line contains one integer t (1≤t≤5000) — the number of test cases. Then t test cases follow.

The first line of each test case contains one integer n (1≤n≤2⋅10^5) — the number of the words in the sequence. Then n lines follow, each of them contains a word — a non-empty string consisting of lowercase letters of the Latin alphabet. The words in the sequence may be non-distinct (i. e. duplicates are allowed). Only the letters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ may occur in the words.

It is guaranteed that the sum of n over all test cases doesn’t exceed 2⋅10^5; the sum of the lengths of all words over all test cases doesn’t exceed 4⋅10^5.

Output
For each test case, output the maximum number of words that compose an interesting story. Print 0 if there’s no way to make a non-empty interesting story.

Example
input
6
3
bac
aaada
e
3
aba
abcde
aba
2
baba
baba
4
ab
ab
c
bc
5
cbdca
d
a
d
e
3
b
c
ca
output
3
2
0
2
3
2

Note
In the first test case of the example, all 3 words can be used to make an interesting story. The interesting story is “bac aaada e”.

In the second test case of the example, the 1-st and the 3-rd words can be used to make an interesting story. The interesting story is “aba aba”. Stephen can’t use all three words at the same time.

In the third test case of the example, Stephen can’t make a non-empty interesting story. So the answer is 0.

In the fourth test case of the example, Stephen can use the 3-rd and the 4-th words to make an interesting story. The interesting story is “c bc”.

题目大致意思为:给你n个字符串 要求输出能组成interesting故事的单词个数 interesting故事的要求:出现abcde中字母次数出现最多的要大于其余四个字母总的出现次数。
//比赛的时候一直没读懂题意…

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
char s[400005];
string str[200005];
int t, n, ans;
int a[200005];
int f(char c)
{for (int i = 0; i < n; i++){a[i] = 0;}for (int i = 0; i < n; i++)//假设当前字母是最大次数 求出每行字符串与当前字母次数的差 {for (int j = 0; j < str[i].length(); j++){if (str[i][j] == c){a[i]++;}else{a[i]--;}}}sort(a,a+n);reverse(a, a + n);//倒序排列int sum = 0;for (int i = 0; i < n; i++){sum += a[i];if (sum <= 0)//如果其余字母出现的次数大于出现最多的字母次数{return i;}}return n;
}
int main()
{cin >> t;while (t--){cin >> n;for (int i = 0; i < n; i++){cin >> s;str[i] = s;}ans = 0;for (int i = 0; i < 5; i++){ans = max(ans, f('a' + i));}cout << ans << endl;}return 0;
}

Day 12 C. Interesting Story相关推荐

  1. 给Linux系统/网络管理员的nmap的29个实用例子

    Nmap亦称为Network Mapper(网络映射)是一个开源并且通用的用于Linux系统/网络管理员的工具.nmap用于探查网络.执行安全扫描.网络核查并且在远程机器上找出开放端口.它可以扫描在线 ...

  2. Nmap——主机、端口扫描工具

    nmap 其基本功能有三个,一是探测一组主机是否在线:其次是扫描主机端口,嗅探所提供的网络服务:还可以推断主机所用的操作系统 . 这是百度给的介绍:http://baike.baidu.com/lin ...

  3. Nmap命令的常用实例

    一.Nmap简介 nmap是一个网络连接端扫描软件,用来扫描网上电脑开放的网络连接端.确定哪些服务运行在哪些连接端,并且推断计算机运行哪个操作系统(这是亦称 fingerprinting).它是网络管 ...

  4. Nmap命令详解(全)

    目录(觉得对你有用的话,记得点个赞再走哦~片尾有学习路线~) nmap简介 1. 用主机名和IP地址扫描系统 2.扫描使用"-v"选项 3.扫描多台主机 4.扫描整个子网 5.使用 ...

  5. DRAM书籍笔记 - 目录整理

    目录 Part 1 Cache An Overview of Cache Principles 1.1 Caches, 'Caches,' and "Caches" 1.2 Loc ...

  6. 系统启动没有声音,音量控制图标不能正常显示,但realplayer能正常播放

    最近碰到了一个问题,任务栏的音量显示图标突然不能正常显示(卸载程序造成),造成计算机启动.注销等 没有声音,swf文件播放不正常,为此很是苦恼了一下,在网上查了一些资料,都是一些陈词烂调,比如 1.到 ...

  7. Interesting Finds: 2007.12.19

    Other: 我不是一名互动设计师,但我曾经是... JavaScript: Working aroung the instanceof memory leak SQLServer: SQL Serv ...

  8. 操作系统学习:Linux0.12初始化详细流程-进程1调度与读取硬盘数据

    本文参考书籍 1.操作系统真相还原 2.Linux内核完全剖析:基于0.12内核 3.x86汇编语言 从实模式到保护模式 4.Linux内核设计的艺术 ps:基于x86硬件的pc系统 Linux0.1 ...

  9. 12.term_vectors查看

    文章目录 1. Term Vectors 简介 1. 返回值 2. term过滤 3. 示例:自动生成term向量 4. 示例:request 中传入doc 5. Per-field 分析器 6. 示 ...

最新文章

  1. sizeof(函数名)=?
  2. js 和C# ashx之间数组参数传递问题
  3. 201421123042 《Java程序设计》第8周学习总结
  4. 基于顺序存储结构的图书信息表的旧图书的出库(C++)
  5. 关于Java Collections Framework的一些总结(2)
  6. 在计算机中添加用户名和密码是多少,在win7系统中添加网络打印机提示输入用户名和密码的解决方案...
  7. CentOS 通过yum来升级php到php5.6,yum upgrade php 没有更新包怎么办?
  8. 批处理计算n天前\后的日期
  9. ubuntu截图工具KSnapshot(静态图),peek(动态图)
  10. link st 量产工具_STM32 ST-LINK Utility介绍、下载、安装、使用方法
  11. Windows环境下Redis安装与配置的两种方式
  12. flutter项目引入iconfont【阿里巴巴图标】的图标
  13. MySQL8.0超细致下载安装教程
  14. 自动化爬虫selenium基础教程
  15. SpringBoot + Vue 前后端分离项目部署到服务器上
  16. 【5G核心网】free5GC UPF源码分析
  17. unittest的基础应用
  18. 从原型图到成品:步步深入 CSS 布局
  19. 千亿元宇宙市场,Soul、映客的新动力
  20. 313分的计算机网络专科学校,2021年高考313分左右能上什么大学(100所)

热门文章

  1. 2020 全球经济正进入衰退期
  2. 关于xamarin汉字转换成拼音
  3. 【我命由我不由天】30多岁的大龄程序员,应该如何保持职场竞争力?
  4. java 多线程 迅雷_Java 仿迅雷多线程下载
  5. 怎么拿到属于自己的那份心仪的offer
  6. 数加使用自定义调度资源进行数据同步
  7. 【LeetCode】老虎证券面试-括号嵌套且满足优先级
  8. 李群和李代数——公式推导(1)
  9. LUA 和 JAVA 的区别
  10. 一键安装JDK和JRE并自动配置Java环境变量