我这个英语学渣又把题给翻译错了……(话说,六级差十分没有过,好心疼T T),题目中说的P和Q都是计算game的个数,我以为是出现的次数,各种wa。。后来调整了以后又是各种wa,原来是double型的数据在排序的时候需要注意一下,我们需要给定一个精度,按照一定的规则来进行排序,比如当两个 rate  < eps 的时候,我们判断分母的大小,让分母大或者分子小的优先排序,这样就能尽可能地避免精度问题。

  总之,题目不难,暴力枚举就可以,但是想一次AC还是挺难的。

  代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
#define N 20010
#define eps 1e-7
map<string,int> vis;
struct OUT
{
string mel;
int p,q;
double rate;
}out[N];
void Find_pq(int &p,int &q,string *str,int *suc,int n,int k,string aim)
{
int lens;
string tmp;
for(int i = ; i < n; i++)
{
lens = str[i].length();
for(int j = ; j < lens; j++)
{
if(k+j > lens) break;
tmp = "";
for(int u = ; u < k; u++)
{
tmp += str[i][j+u];
}
if(tmp == aim)
{
p++;
if(suc[i]) q++;
break;
}
}
}
}
bool cmp(OUT o1,OUT o2){
if(fabs(o1.rate-o2.rate) < eps){
if(o1.p != o2.p) return o1.p > o2.p;
else return o1.mel < o2.mel;
}
else return o1.rate < o2.rate;
}
string Slove(int cnt){
if(cnt==) return "No solution";
sort(out,out+cnt,cmp);
return out[].mel;
}
int main()
{
int ca=,lens,m,k,n,cnt,suc[];
string str[],jud,ans,tmp;
while(cin>>n && n)
{
cin>>m>>k;
cnt = ;
for(int i = ; i < n; i++)
{
cin>>str[i]>>jud;
if(jud == "Yes") suc[i] = ;
else suc[i] = ;
}
vis.clear();
for(int i = ; i < n; i++)
{
lens = str[i].length();
for(int j = ; j < lens; j++)
{
if(k+j > lens) break;
tmp = "";
for(int u = ; u < k; u++)
{
tmp += str[i][j+u];
}
if(vis[tmp]) continue;
vis[tmp] = ;
int p1,q1;
int &p = p1,&q = q1;
p = q = ;
Find_pq(p,q,str,suc,n,k,tmp);///引用大法好
// cout<<tmp<<" "<<p1<<" "<<q1<<endl;
if(p < m) continue;
out[cnt].p = p1;
out[cnt].q = q1;
out[cnt].mel = tmp;
out[cnt].rate = q1*1.0 / p1;
cnt++;
}
}
ans = Slove(cnt);
cout<<"Case "<<++ca<<": "<<ans<<endl;
}
return ;
}

UVALive - 4026 Difficult Melody(暴力)的更多相关文章

  1. Difficult Melody(映射)

    题目链接 http://vjudge.net/contest/137242#problem/D Description You're addicted to a little game called ...

  2. Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)

    题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...

  3. UVALive 4423 String LD 暴力

    A - String LD Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Stat ...

  4. UVaLive 3401 Colored Cubes (暴力)

    题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...

  5. UVaLive 7461 Separating Pebbles (暴力)

    题意:给出平面上的两类点,判断是否能画一条直线将两类点完全分割开来. 析:用暴力去枚举任意两点当作直线即可. 代码如下: #pragma comment(linker, "/STACK:10 ...

  6. UVALive 6912 Prime Switch 暴力枚举+贪心

    题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  7. UVALive 6855 Banks (暴力)

    Banks 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/A Description http://7xjob4.com1.z0 ...

  8. UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  9. UVaLive 6625 Diagrams & Tableaux (状压DP 或者 DFS暴力)

    题意:给一个的格子图,有 n 行单元格,每行有a[i]个格子,要求往格子中填1~m的数字,要求每个数字大于等于左边的数字,大于上边的数字,问有多少种填充方法. 析:感觉像个DP,但是不会啊...就想暴 ...

随机推荐

  1. HDtune(硬盘检测) V5.5 中文绿色版

    软件名称:HDtune(硬盘检测) V5.5 中文绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win 32位/64位软件大小: 565KB 图片预览: 软件简介:HD Tune Pro一 ...

  2. spring AOP 代理机制、执行过程、四种实现方式及示例详解

    1.加载过程 spring首先检测配置文件中的代理配置,然后去加载bean; 如果配置文件中没有配置代理,自然代理不会生效,如果配置了代理,但是代理还没有生效,那么有可能是加载顺序的问题,即在检测到代 ...

  3. java使用url和tns两种方式连接数据库执行存储过程

    1.url方式(连接数据库并执行一个查询): public static void main(String[] args) throws ClassNotFoundException, SQLExce ...

  4. Hash算法冲突解决方法分析

    采用开放定址法处理散列表的冲突时,其平均查找长度?  高于链接法处理冲突 低于二分查找 开放定址法:一旦发生冲突,就去寻找下一个空的散列地址,只要散列地址够大,空的地址总会找到 链地址法: 一旦发生冲 ...

  5. Oracle字符串操作[转:http://www.cnblogs.com/xd502djj/archive/2010/08/11/1797577.html]

    ORACLE 字符串操作 1 字符串连接   SQL> select 'abc' || 'def' from dual; 'ABC'|------abcdef 2 小写SQL>select ...

  6. play框架概述

    今天是来百度实习的第四天,在项目过程中mentor说会用到play框架,当时就一个晕啊.Java还有一个叫play框架,作为一个从大三开始用java的重度javaer,居然不知道这个框架的存在,内心一 ...

  7. eclipse代码提示优化

    用Eclipse编写Android程序的代码提示功能主要是在java和xml文件中,有时候会失效,默认的提示功能有限. 1)java文件自动提示      Window->Preferences ...

  8. ios电话拨打进行监听电话状态

    #import "ViewController.h" #import <CoreTelephony/CTCallCenter.h> #import <CoreTe ...

  9. VBS脚本代码(手工编写---在windows 7上调用系统对话框,来选择文件)

    '=========================================================================='' VBScript Source File - ...

  10. DOM操作-克隆元素

    代码: ———————————————————————————— <script type="text/javascript">            //克隆元素   ...