USACO 3.2 Contact
Contact
IOI'98
The cows have developed a new interest in scanning the universe outside their farm with radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right from the centre of the galaxy. They wish to know if the emission is transmitted by some extraterrestrial form of intelligent life or if it is nothing but the usual heartbeat of the stars.
Help the cows to find the Truth by providing a tool to analyze bit patterns in the files they record. They are seeking bit patterns of length A through B inclusive (1 <= A <= B <= 12) that repeat themselves most often in each day's data file. They are looking for the patterns that repeat themselves most often. An input limit tells how many of the most frequent patterns to output.
Pattern occurrences may overlap, and only patterns that occur at least once are taken into account.
PROGRAM NAME: contact
INPUT FORMAT
Line 1: | Three space-separated integers: A, B, N; (1 <= N ≤ 50) |
Lines 2 and beyond: | A sequence of as many as 200,000 characters, all 0 or 1; the characters are presented 80 per line, except potentially the last line. |
SAMPLE INPUT (file contact.in)
2 4 10
01010010010001000111101100001010011001111000010010011110010000000
In this example, pattern 100 occurs 12 times, and pattern 1000 occurs 5 times. The most frequent pattern is 00, with 23 occurrences.
OUTPUT FORMAT
Lines that list the N highest frequencies (in descending order of frequency) along with the patterns that occur in those frequencies. Order those patterns by shortest-to-longest and increasing binary number for those of the same frequency. If fewer than N highest frequencies are available, print only those that are.
Print the frequency alone by itself on a line. Then print the actual patterns space separated, six to a line (unless fewer than six remain).
SAMPLE OUTPUT (file contact.out)
23
00
15
01 10
12
100
11
11 000 001
10
010
8
0100
7
0010 1001
6
111 0000
5
011 110 1000
4
0001 0011 1100 ————————————————————————————————————————————————
一道普通的字典树应用,整理一下语言细节……
一是系统自带的类型自己不能再重载运算符了,要再struct一个类型
还有就是这道题的输出格式【如果有人能看我这个蒟蒻的题解的话……】
六个一排,然后短的串在前面,长的串在后面,相同长度的串才是字典序
/*
ID: ivorysi
PROG: contact
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define inf 0x7fffffff
#define MAXN 400005
#define ivorysi
#define mo 97797977
#define ha 974711
#define ba 47
#define fi first
#define se second
//#define pis pair<int,string>
using namespace std;
typedef long long ll;
int tree[];
string s;
int a,b,n;
struct pis {
int first;string second;
};
bool operator < (pis c,pis d) {
if(c.fi!=d.fi) return c.fi<d.fi;
else if(c.se.length()!=d.se.length()) return c.se.length() > d.se.length();
else return c.se > d.se;
}
priority_queue<pis> mq;
void dfs(int u,int t,string str){
if(t>b) return;
if(t>=a && tree[u]!=) {
mq.push((pis){tree[u],str});
}
dfs(u<<,t+,str+"");
dfs(u<<|,t+,str+"");
}
void solve() {
scanf("%d%d%d",&a,&b,&n);
string tm;
while(cin>>tm) s+=tm;
int t=s.length();
xiaosiji(i,,t) {
int tmp=;
int l=min(b,t-i);
xiaosiji(j,,l) {
if(s[i+j]=='') tree[tmp<<=]++;
else tree[tmp=(tmp<<)+]++;
}
}
dfs(,,"");
while(n>) {
int cnt=;
pis p=mq.top();mq.pop();
printf("%d\n%s",p.fi,p.se.c_str());
++cnt;
if(mq.empty()) {puts("");break;}
while(mq.top().fi==p.fi) {
if(cnt==) {puts("");cnt=;}
else printf(" ");
printf("%s",mq.top().se.c_str());
mq.pop();
++cnt;
}
puts("");
--n;
}
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("contact.in","r",stdin);
freopen("contact.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
}
USACO 3.2 Contact的更多相关文章
- USACO 3.1 Contact
http://www.nocow.cn/index.php/Translate:USACO/contact 题目大意:给一个只含0和1的序列,统计每个子序列的重复次数,并按次数递减来输出 考虑子序列时 ...
- 【USACO 3.1】Contact(01子串按出现次数排序)
题意:给你一个01字符串,将长度为a到b之间(包含a.b)的子串按照出现次数排序.注意输入输出格式 题解:01子串对应一个二进制,为了区别11和011这样的不同子串,我们把长度也记录下来,官方题解是在 ...
- USACO Section 3.1: Contact
算法简单,写起来遇到些小问题 /* ID: yingzho1 LANG: C++ TASK: contact */ #include <iostream> #include <fst ...
- 洛谷P2724 联系 Contact
P2724 联系 Contact 17通过 86提交 题目提供者该用户不存在 标签 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 题目背景 奶牛们开始对用射电望远镜扫描牧场外的宇宙感 ...
- USACO 2016 January Contest, Gold解题报告
1.Angry Cows http://www.usaco.org/index.php?page=viewproblem2&cpid=597 dp题+vector数组运用 将从左向右与从右向左 ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
- 【USACO 3.1】Stamps (完全背包)
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...
- USACO翻译:USACO 2013 NOV Silver三题
USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...
- USACO翻译:USACO 2013 DEC Silver三题
USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...
随机推荐
- vim简单的实用总结
vim简单的实用总结 介绍vim常用的四种模式:一般模式,编辑模式,指令列命令模式与可视模式.一,一般模式 用vim filename打开文件后直接进入的就是一般模式,在这个模式下可以用hjkl移 ...
- 关于sscanf函数的各种详细用法
看书的时候碰到sscanf函数,就上网查了很多资料,并加以自己的整理,希望对大家有所帮助. (因为参考的博客太多太散,就不一一注明,望大神们见谅) sscanf() :从一个字符串中读进与指定格式相 ...
- WebForm和Asp.Net MVC的理解
我对WebForm和Asp.Net MVC的理解 比较WebForm和Mvc的请求处理方式 首先简单了解一下Asp.Net中怎么对页面进行请求处理的: 在管道的第7-8个事件之间,有一个MapHt ...
- 当Azure里的虚拟机网卡被禁用
当Azure里的虚拟机网卡被禁用了之后…… 这样的想法来自于一个假设,如果网卡被禁用之后,用户该如何处理,Azure又该如何处理,对于设置在虚拟机中的禁用网卡选项是否还有存在的意义?通常情况下,点选了 ...
- jQuery event的复制粘贴的坑
jQuery为了兼容性会把系统暴露出来的event重新整理一遍,但是复制粘贴的event就被丢掉了. 所以要在所有原生浏览器想实现复制粘贴,大家都用flash实现了.其实只要用原生的方法捕获事件就ok ...
- T_SQL查询语句(一): 单表查询
############################################ 查询语句--SELECT ########################################## ...
- 乔布斯,TED,我的演讲
乔布斯传这部独立影片虽然以失败告终,但是人们把期待留给了索尼影业即将投拍的官方乔布斯传记电影. 据传,这部影片将以乔布斯最成功的四次演讲作为主线,这无疑说明,演讲,对于乔布斯这个传奇人物,是非常重要的 ...
- 一步一步深入spring(2)-三种方式来实例化bean
在一步一步深入spring(1)--搭建和测试spring的开发环境中提到了一种实例化bean的方式,也是最基本的使用构造器实例化bean 1.使用构造器实例化bean:这是最简单的方式,Spring ...
- 使用Varnish+ESI实现静态页面的局部缓存(思路篇)
使用Varnish+ESI实现静态页面的局部缓存(思路篇) 页面静态化是搭建高性能网站必用的招式之一,页面静态化可以有效提升系统响应速度,同时也有利于搜索引擎优化.但在页面静态化后,静态页面之间包含( ...
- 使用ResourceDictionary管理Logical Resources
WPF整理-使用ResourceDictionary管理Logical Resources “Logical resources may be of various types, such as br ...