UVALive - 4026 Difficult Melody(暴力)
我这个英语学渣又把题给翻译错了……(话说,六级差十分没有过,好心疼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(暴力)的更多相关文章
- Difficult Melody(映射)
题目链接 http://vjudge.net/contest/137242#problem/D Description You're addicted to a little game called ...
- Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)
题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...
- UVALive 4423 String LD 暴力
A - String LD Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Stat ...
- UVaLive 3401 Colored Cubes (暴力)
题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...
- UVaLive 7461 Separating Pebbles (暴力)
题意:给出平面上的两类点,判断是否能画一条直线将两类点完全分割开来. 析:用暴力去枚举任意两点当作直线即可. 代码如下: #pragma comment(linker, "/STACK:10 ...
- UVALive 6912 Prime Switch 暴力枚举+贪心
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- UVALive 6855 Banks (暴力)
Banks 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/A Description http://7xjob4.com1.z0 ...
- UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVaLive 6625 Diagrams & Tableaux (状压DP 或者 DFS暴力)
题意:给一个的格子图,有 n 行单元格,每行有a[i]个格子,要求往格子中填1~m的数字,要求每个数字大于等于左边的数字,大于上边的数字,问有多少种填充方法. 析:感觉像个DP,但是不会啊...就想暴 ...
随机推荐
- LeetCode OJ 34. Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- jQuery 事件 - bind() 方法
定义和用法 bind() 方法为被选元素添加一个或多个事件处理程序,并规定事件发生时运行的函数. 实例1(一个事件) 记得把js引用地址换掉 当点击鼠标时,隐藏或显示 p 元素: <html&g ...
- Python笔记2-20151023
一.循环 Python的循环有两种,一种是for...in循环,依次吧list或tuple中的每个元素迭代出来. >>>names = ['Michael','Bob','Tracy ...
- Windows kernel pool 初探(2014.12)
Windows kernel pool 1. 简介 Kernel pool类似于Windows用户层所使用Heap,其为内核组件提供系统资源.在系统初始化的时候,内存管理模块就创建了pool. 严格的 ...
- android 按钮Button单击背景切换
res/drawable/btn_selected.xml <?xml version="1.0" encoding="utf-8"?> <s ...
- Xbox360自制系统GOD包安装教程
1.准备工作 U盘或移动硬盘一个,已下载好的GOD包,本教程用一个32G的U盘和游戏<猎天使魔女>为例. 右击U盘,属性,查看你的U盘是否为FAT32格式. 如果是FAT32格式,则可直接 ...
- python常用函数年初大总结
1.常用内置函数:(不用import就可以直接使用) help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像函数一样调用 repr(obj) 得到o ...
- 批量创建IP方法
以下教程,将告诉大家如何在Windows系统中通过命令行,批量添加IP.目标,在本机的的网卡名称为“本地连接”的网卡中,批量添加192.168.1段的ip地址,起开始IP为10,每次增加1,知道22为 ...
- 深入理解JAVA的多态性[转]
昨天看到一个关于多态性的帖子,参考了回帖者的理解,加入了一些自己的看法,整理出来供大家参考,不一定完全正确,欢迎大家批评指正. (一)相关类 class A ...{ public S ...
- $.getjson方法配合在url上传递jsoncallback=?参数,实现跨域获取指定网站某商品访问量
across.php文件在域名www.cms.com程序中 <html><body><div id="pv">99</div>< ...