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,但是不会啊...就想暴 ...
随机推荐
- 多线程---优先级&yield方法
优先级只有10级,1-10.最高10(java中用Thread.MAX_PRIORITY),最低1,中间级5. 设置优先级的方法是 线程对象.setPriority(5): yield : 暂停(不是 ...
- 监控mysql主从
这里记录了,每次都百度查询多次. zabbix默认包含mysql监控 其中包含 mysql的基本状态监控 MySQL主从监控需要结合自定义 1)目前项目需求 只对 Slave_IO_Running . ...
- 【Echarts每天一例】-1
官方网址:http://echarts.baidu.com/doc/example/line1.html 使用百度echarts官方实例:http://ask.csdn.net/questions/1 ...
- SQL函数学习(二):DATEADD() 函数
DATEADD() 函数在日期中添加或减去指定的时间间隔. 语法 DATEADD(datepart,number,date) date 参数是合法的日期表达式.number 是您希望添加的间隔数:对于 ...
- visible绑定(The "visible" binding)
对visible进行绑定可以控制元素的显示和隐藏. 示例: <div data-bind="visible: shouldShowMessage"> You will ...
- php 好用的函数
extract — 从数组中将变量导入到当前的符号表,数组的键将作为新的变量,数组的值将最为新变量的值
- Raft详解-启动后运行期间代码
Raft启动后运行期间主要执行两个函数:1.状态监测和转化 func (rf *Raft) Loop() { // Set out as a follower TimeOutConst := 0 fo ...
- 基于Centos6.6的R720服务器四网口端口聚合的实践
服务器多网口端口聚合,其目的主要在于网卡容灾和提升带宽.linux端口绑定,提供7种模式,如下: 关于mode共有0-6等7种模式,详细请参考官方手册!mode的值表示工作模式,他共有0,1,2,3, ...
- 阅读http://zh.lucida.me/有感
lucida大神本科毕业于大工,研究生毕业于北航,有这样的学历在社会上混就已经绰绰有余了,但是lucida神并不满足,刻苦努力,拼搏进取,最后进入google london工作,曾经一度在micros ...
- java操作cookies
建立一个无生命周期的cookie,即随着浏览器的关闭即消失的cookie,代码如下 HttpServletRequest request HttpServletResponse response Co ...