题目链接

http://vjudge.net/contest/137242#problem/D

Description

You're addicted to a little game called `remember the melody': you hear some notes, and then you repeat it. In most cases, the longer the melody, the harder to repeat, but it isn't always true. Also, melodies of the same length are usually not equally easy to remember. To find a way to define the remember difficulty of a melody, you invented a statistics-based model:

Suppose you're investigating melodies of a particular length. If a melody appeared in p games, among which you successfully repeated q games, the smaller q/p , the more difficult the melody. If there is more than one melody having the minimal ratio, the one with larger p is considered more difficult. But there is an exception: if p is smaller than a threshold m , you simply ignore it (you can't call it difficult if you haven't tried it a lot of times, can you?). The melody appears in a game if its string representation is a consecutive substring occurring at least once in that game.

Write a program to find the most difficult melody of length k , given n games you've played.

Input

The input contains several test cases. Each case consists of three integers n, m, k (1<=m<=n<=100, 1<=k<=20 ) , the next n lines each contain two strings separated by exactly one space: the game, and whether you successfully repeated it. The first string will contain at least one at most 100 upper case letters `C', `D', `E', `F', `G', `A', `B'. The second string will be either `Yes' or `No' (case sensitive). The last test case is followed by a single zero, which should not be processed.

Output

For each test case, print the case number and the most difficult melody. If there is more than one solution, output the lexicographically smallest one. If there is no solution, output the string `No solution'.

Sample Input

3 2 3
EEECEG Yes
BFCEG No
DEBFCEGEEC No
3 2 2
AAA No
BBB No
CCC Yes
0

Sample Output

Case 1: BFC
Case 2: No solution 题意:输入n,m,k 接下来的n行,每行输入一个1~100的字符串(只包含大写字母`C', `D', `E', `F', `G', `A', `B'),然后输入"Yes" 或者"No" 求其中长为k的最难字符串,最难字符串定义如下:设这个子串在n个串中出现p次,在表示为"Yes"的串中出现q次,在同一个串中不重复计算只算一次,q/p比值越小难度越大,并且要保证p>=m 否则不考虑这个字符串,如果有多个字符串比值相同,输出p较大的支付串,如果有多个p也相同,输出字典序较小的字符串; 思路:用两个集合分别记录这些长为k的子串在n个串中出现的次数和在"Yes"表示的串中出现的次数; 代码如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
map<string,int>mp1;
map<string,int>mp2;///Yes;
map<string,int>mp3;
map<string,int>::iterator it; int main()
{
int n,m,k,Case=;
while(scanf("%d",&n)&&n)
{
scanf("%d%d",&m,&k);
mp1.clear();
mp2.clear();
char s1[],s2[];
for(int j=; j<n; j++)
{
scanf("%s%s",s1,s2);
int len=strlen(s1);
mp3.clear();
for(int i=len-k; i>=; i--)
{
s1[i+k]='\0';
string s=(string)(s1+i);
if(mp3[s]==){
mp3[s]++;
mp1[s]++;
if(s2[]=='Y') mp2[s]++;
}
}
}
int t1=,t2=;
string str="";
for(it=mp1.begin(); it!=mp1.end(); it++)
{
if(it->second>=m)
{
int w1=mp2[it->first];
int w2=it->second;
int f=w1*t2-w2*t1;
if(f<||f==&&w2>t2||f==&&w2==t2&&(str>(it->first)))
{
str="";
str+=it->first;
t1=w1;
t2=w2;
}
}
}
printf("Case %d: ",Case++);
if(t1==&&t2==) puts("No solution");
else cout<<str<<endl;
}
return ;
}
 

Difficult Melody(映射)的更多相关文章

  1. UVALive - 4026 Difficult Melody(暴力)

    我这个英语学渣又把题给翻译错了……(话说,六级差十分没有过,好心疼T T),题目中说的P和Q都是计算game的个数,我以为是出现的次数,各种wa..后来调整了以后又是各种wa,原来是double型的数 ...

  2. .apk等常用文件下载出现如果应下载文件,请添加 iis MIME 映射。

    在下载.apk文件时出现错误. HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. ...

  3. Linux mem 2.6 Rmap 内存反向映射机制

    文章目录 1. 简介 2. 匿名内存 Rmap 的建立 2.1 fork() 2.2 do_page_fault() 3. 文件内存 Rmap 的建立 3.1 fork() 3.2 do_page_f ...

  4. Hibernatel框架关联映射

    Hibernatel框架关联映射 Hibernate程序执行流程: 1.集合映射 需求:网络购物时,用户购买商品,填写地址 每个用户会有不确定的地址数目,或者只有一个或者有很多.这个时候不能把每条地址 ...

  5. hibernate多对多关联映射

    关联是类(类的实例)之间的关系,表示有意义和值得关注的连接. 本系列将介绍Hibernate中主要的几种关联映射 Hibernate一对一主键单向关联Hibernate一对一主键双向关联Hiberna ...

  6. Dapper逆天入门~强类型,动态类型,多映射,多返回值,增删改查+存储过程+事物案例演示

    Dapper的牛逼就不扯蛋了,答应群友做个入门Demo的,现有园友需要,那么公开分享一下: 完整Demo:http://pan.baidu.com/s/1i3TcEzj 注 意 事 项:http:// ...

  7. ElasticSearch 5学习(9)——映射和分析(string类型废弃)

    在ElasticSearch中,存入文档的内容类似于传统数据每个字段一样,都会有一个指定的属性,为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成字符串值,Elasticsearc ...

  8. .NET平台开源项目速览(14)最快的对象映射组件Tiny Mapper

    好久没有写文章,工作甚忙,但每日还是关注.NET领域的开源项目.五一休息,放松了一下之后,今天就给大家介绍一个轻量级的对象映射工具Tiny Mapper:号称是.NET平台最快的对象映射组件.那就一起 ...

  9. ASP.NET Core的路由[1]:注册URL模式与HttpHandler的映射关系

    ASP.NET Core的路由是通过一个类型为RouterMiddleware的中间件来实现的.如果我们将最终处理HTTP请求的组件称为HttpHandler,那么RouterMiddleware中间 ...

随机推荐

  1. 《R in Action》读书笔记(2)

    MindMapper 原文件

  2. Tornado框架中视图模板Template的使用

    上文的程序中有这样一段: class MessageHandler(tornado.web.RequestHandler): def get(self): self.write(''' <htm ...

  3. Java 循环中标签的作用

    continue和break可以改变循环的执行流程,但在多重循环中,这两条语句无法直接从内层循环跳转到外层循环.在C语言中,可以通过goto语句实现多重循环的跳转,但在非循环结构中使用goto语句会使 ...

  4. NULL的陷阱:Merge

    NULL表示unknown,不确定值,所以任何值(包括null值)和NULL值比较都是不可知的,在on子句,where子句,Merge或case的when子句中,任何值和null比较的结果都是fals ...

  5. SQL Server中的窗口函数

    简介     SQL Server 2012之后对窗口函数进行了极大的加强,但对于很多开发人员来说,对窗口函数却不甚了解,导致了这样强大的功能被浪费,因此本篇文章主要谈一谈SQL Server中窗口函 ...

  6. 【WP开发】加密篇:双向加密

    说起双向加密,如果以前在.NET开发中弄过加/解密的朋友都不会陌生,常用的算法有DES.AES等.在RT应用程序中,也提供了加密相关的API,算法自然是一样的,只是API的封装方式不同罢了,因为RT不 ...

  7. ASP.NET Core中的依赖注入(5): ServiceProvider实现揭秘 【解读ServiceCallSite 】

    通过上一篇的介绍我们应该对实现在ServiceProvider的总体设计有了一个大致的了解,但是我们刻意回避一个重要的话题,即服务实例最终究竟是采用何种方式提供出来的.ServiceProvider最 ...

  8. Thrift简单实践

    0.什么是RPC RPC(Remote Procedure Call - 远程过程调用),是通过网络从远程计算机上请求服务,而不需要了解底层网路技术的细节.简单点说,就是像调用本地服务(方法)一样调用 ...

  9. 利用angular结合translate为项目实现国际化

    前言 利用H5项目第一版本已经上线,话说有了第一期就有了第二期,这不要为第二期做准备了,老大发话第一件事就要利用Angular JS实现项目的国际化以及后续要借助这个框架来实现其他功能,好吧我表示没怎 ...

  10. Ubuntu杂记——链接ln的使用:创建和删除符号链接

    原文链接:http://blog.csdn.net/janpylx/article/details/6761910 一 . 使用方式 ln [option] source_file dist_file ...