题目链接

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. android服务里生成通知点击后返回正在运行的程序和当前的Activity

    想在服务里生成一个通知,并且点击通知打开当前应用程序下单当前活动,折腾了半天,网上的那些都不靠谱,试了半天,最后把ActivityManager和反射都用进来了,终于解决了这个问题.这样在服务中想恢复 ...

  2. [转]GC简介

    [转]GC简介 原文链接:http://www.cnblogs.com/cposture/p/4845189.html 原文写得太好了,这里转一下. 1 GC机制 1.1 对象 从计算机的角度,装有数 ...

  3. linux下使用adb连接android手机

    一.新建文件 cat /etc/udev/rules.d/51-android.rules SUBSYSTEM==" 二.重启 udev sudo /etc/init.d/udev rest ...

  4. Senparc.Weixin.MP SDK 微信公众平台开发教程(十七):个性化菜单接口说明

    前不久微信上线了个性化菜单接口,Senparc.Weixin SDK也已经同步更新. 本次更新升级Senparc.Weixin.MP版本到v13.5.2,依赖Senparc.Weixin版本4.5.4 ...

  5. java线程 公平锁 ReentrantLock(boolean fair)

    一.公平锁 1.为什么有公平锁 CPU在调度线程的时候是在等待队列里随机挑选一个线程,由于这种随机性所以是无法保证线程先到先得的(synchronized控制的锁就是这种非公平锁).但这样就会产生饥饿 ...

  6. JAVAScript控制多个下拉框

    方法:获取多选下拉框对象数组→循环判断option选项的selected属性(true为选中,false为未选中)→使用value属性取出选中项的值.实例演示如下: 这个东西我是在百度上查的,我为了方 ...

  7. uwp如何建立任何形状的头像,如圆形,方形,六边形等

    最近掌上英雄联盟更新了新的界面,其中“我”界面的更新比较大,我目前还在加紧跟进.在做这个界面的时候,这个头像我想了一下,其实挺好解决的.先上个原图 这个头像一开始我也完全找不到头绪,然后我把头像放大了 ...

  8. 移动端HTML5<video>视频播放优化实践

    遇到的挑战 移动端HTML5使用原生<video>标签播放视频,要做到两个基本原则,速度快和体验佳,先来分析一下这两个问题. 下载速度 以一个8s短视频为例,wifi环境下提供的高清视频达 ...

  9. MVC4做网站后台:栏目管理1、添加栏目

    把栏目添加删除跟前台混在一起结构清晰,现在有了后台管理的区域就把后台管理相关的代码分开. 要实现功能: 1.添加栏目 2.删除栏目 3.修改栏目信息 -- 一.开始 1.添加 接口InterfaceC ...

  10. 深入学习jQuery选择器系列第二篇——过滤选择器之子元素选择器

    × 目录 [1]通用形式 [2]反向形式 [3]首尾元素 [4]唯一元素 前面的话 在上一篇中已经介绍过基础选择器和层级选择器,本文开始介绍过滤选择器.过滤选择器是jQuery选择器中最为庞大也是最为 ...