我这个英语学渣又把题给翻译错了……(话说,六级差十分没有过,好心疼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. wuzhi 五指 数据库仿 thinkphp

    在/coreframe/app/模块/libs/class/mydb.class.php 中编辑 调用 : $mydb = load_class("mydb","模块&q ...

  2. chapter9_4 非抢占式的多线程

    协同程序与常规的多线程不同之处:协同程序是非抢占式的. 当一个协同程序运行时,是无法从外部停止它的.只有当协同程序显式地调用yield时,它才会停止. 当不存在抢先时,编程会变得简单很多,无须为同步的 ...

  3. List<string> to List<decimal> by C# 2.0

    List<" } ); List<decimal> temp = data.ConvertAll<decimal>(delegate(string x) { r ...

  4. The Linux Storage Stack Diagram 内核 4.0 版的 I/O 栈

  5. Core Animation中的基础动画

    基础动画 在开发过程中很多情况下通过基础动画就可以满足开发需求,前面例子中使用的UIView代码块进行图像放大缩小的演示动画也是基础动画(在iOS7 中UIView也对关键帧动画进行了封装),只是UI ...

  6. Silverlight中如何自己写方法将DataTable转换为PagedCollectionView数据(动态创建类)

    将DataTable转换为PagedCollectionView数据,我们可以借用DataTable的GetBindableData()方法,如下: DataTable dt=new DataTabl ...

  7. Linux查找文件中的字符串命令

    grep -nr 'archermind' -r, --recursive Read all files under each directory, recursively, following sy ...

  8. Kmeans聚类算法

    K-means也是聚类算法中最简单的一种了,但是里面包含的思想却是不一般.最早我使用并实现这个算法是在学习韩爷爷那本数据挖掘的书中,那本书比较注重应用.看了Andrew Ng的这个讲义后才有些明白K- ...

  9. point类型·

    指针的类型 不同类型的指针,从内存需求的观点来说,没有什么不同!他们三个都需要足够的内存来繁殖一个机器地址,"指向不同类型之各指针"之间的差异,既不在其指针表示法不同,也不再其内容 ...

  10. LeetCode OJ 257. Binary Tree Paths

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...