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 ...
随机推荐
- map,set的模板[STL]
之前写某题单词查找的时候,有用到set,晚上写codeforces#497 div2 D题有用到map 感觉set,map的功能挺类似的,在此小结: 这里就不具体比较相同点和不同点了,免得看起来乱七八 ...
- jQuery中Ajax的应用
一.Ajax介绍 1.什么是Ajax 异步的JavaScript与XML技术,是一种广泛应用在浏览器的网页开发技术. 2.Ajax的优点 a.不需要任何浏览器插件,在任何支持JavaScript的浏览 ...
- SVN版本冲突解决详解
SVN版本冲突解决详解 分类: SVN(SubVersion)2009-11-23 15:45 27014人阅读 评论(12) 收藏 举报 svnsubversion服务器文档工作c 版本冲突原因: ...
- [google面试CTCI] 1-4.判断两个字符串是否由相同字符组成
[字符串与数组] Q:Write a method to decide if two strings are anagrams or not 题目:写一个算法来判断两个字符串是否为换位字符串.(换位字 ...
- golang环境搭建
golang环境搭建 好久没写博客了,最近加班好厉害,加到自己都觉得不太适合这个行业了,每天头都是沉甸甸的,可惜今年注定不是收获的季节. 最近忙里偷闲在学习nodejs,赶巧看到golang的文章,一 ...
- [置顶] 学习JDK源码:可进一步优化的代码
1.参数化类型的构造函数比较啰嗦 new HashMap<String, List<String>>() 如果你调用参数化类的构造函数,那么很不幸,你必须要指定类型参数,即便上 ...
- RCP:如何把Preferences中的项从一个类别移动到另一个类别 2013-08-23 18:59 by Binhua Liu,
RCP:如何把Preferences中的项从一个类别移动到另一个类别 前言 很久没写文章了,准备写一系列关于Eclipse RCP /Plugin的文章. 这些文章都是trouble shooting ...
- LigerUI权限系统之组织结构
先上图,再看代码.组织结构界面 组织结构添加: 组织结构修改: 组织结构删除: 我在做这个页面的时候treegrid 的远程数据加载让我很头痛,从LigerUI官网提供的Demo来看,它是根据json ...
- VS2012下使用Moq进行单元测试
单元测试虽然是个很老的东西了,但平时写代码一般都不写测试,因为VS调试完全可以满足了,所以一直也就没有用过,刚好在<Pro.ASP.NET.MVC.3.Framework>中看到了Moq这 ...
- spring实现数据库读写分离
现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库.Master库负责数据更新和实时数据查询,Slave库当然负责非实时数据查询.因为在实际的应 ...