我这个英语学渣又把题给翻译错了……(话说,六级差十分没有过,好心疼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. LeetCode OJ 229. Majority Element II

    Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...

  2. poj 1142 Smith Numbers

    Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh U ...

  3. html的表单表格...

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Gentoo: !!! existing preserved libs问题

    问题描述 !!! existing preserved libs: >>> package: media-libs/libmng-2.0.2-r1 * - /usr/lib/libm ...

  5. app测试--稳定性测试

    稳定性测试的概念有2种, 一, 稳定性测试,对应于异常性测试,即发生异常情况时,系统如何反应的测试.包含: 1 交互性测试,被打扰的情况,如来电,短信,低电量等.这些其实在上章的功能测试中有提到. 2 ...

  6. mongoDB5--mongoDB增删改查

    之前我们探讨了mongodb的"增删改查",要知道,我们的增删改其实都离不开查询表达式,所以查询表达式在mongodb是非常重要的.关于查询其实我们只是介绍了以小部分.关于mong ...

  7. iOS开发 自定义UIAlertController的样式

    引言: 关于提示框, 系统自带的提示框有时可能满足不了我们的需求, 比如一个提示框的取消按钮我需要灰色字体显示, 这时候就需要自定义提示框的样式了. 示例图 苹果自iOS8开始,就已经废弃了之前用于界 ...

  8. MFC连接Access讲解(3合1) .

    方法一: 1.首先,要用#import语句来引用支持ADO的组件类型库(*.tlb),其中类型库可以作为可执行程序(DLL.EXE等)的一部分被定位在其自身程序中的附属资源里,如:被定位在msado1 ...

  9. WebDriver使用IE和chrome浏览器

    因为我用的是 selenium-dotnet-2.47.0.zip IEDriverServer_x64下载地址 https://code.google.com/p/selenium/download ...

  10. Chapter 1 First Sight——36

    The door opened again, and the cold wind suddenly gusted through the room, rustling the papers on th ...