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 ...
随机推荐
- 【IOS开发】基础
1.Objective-C 为 ANSI C 添加了下述语法和功能: 定义新的类 类和实例方法 方法调用(称为发消息) 属性声明(以及通过它们自动合成存取方法) 静态和动态类型化 块 (block), ...
- 计算image 积分图
// testopencv.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <opencv2\opencv.hpp& ...
- smtp中ehlo的使用
以前玩smtp的时候申明都是用的helo,最近在整理邮件服务的时候,才知道还有一个叫做ehlo的(太落后了). google了一下,了解了基本上是这么个情况:ehlo是对helo的扩展,即extend ...
- 模块化开发AraeRegistration
.NET/ASP.NET MVC(模块化开发AraeRegistration) 阅读目录: 1.开篇介绍 2.AreaRegistration注册路由(传递路由上下文进行模块化注册) 1]开篇介绍 A ...
- Redis安装介绍
Redis安装介绍 一.Linux版本及配置 1. Linux版本:Red Hat Enterprise Linux 6虚拟机 2. 配置: 内存:1G:CPU:1核:硬盘:20G 二.Redis ...
- RTB撕开黑盒子 Part 0:Pacing: is everyone doing it wrong?
曾尝试为我们的RTB客户解决过Pacing问题,Pacing问题要解决的问题是:如果一个客户给你一笔预算,让你去运营一个广告推广计划,在一定的时间内投放广告,将这笔预算在指内的时间内,比较均匀地将预算 ...
- easyui获取当前点击对象tabs的title
现在如果要关闭一个tab,只能点击该tab上面的x号.现增加双击tab使其关闭. 可使用jquery的bind函数绑定dblclick双击事件 tabs的关闭方法为close 要传一个title参数表 ...
- mmDeferred
前端异步解决方案——mmDeferred Deferred是前端解决异步操作的一种编程范式,后来出现的Promise规范更是让其普适性大大提高.不过Promise规范也存在分岐.现在最流行的是Prom ...
- SP2-1503: 无法初始化 Oracle 调用界面
问题描述: win7下,cmd运行 输入sqlplus报一下错误 SP2-1503: 无法初始化 Oracle 调用界面 SP2-0152: ORACLE 不能正常工作 解决办法 1.cmd右键--以 ...
- Entity Framework实体模型 入门视频教程
Entity Framework实体模型 入门视频教程 恢复内容开始--- 第一步 创建一个 控制台应用程序 第二步 创建一个ADO.NET 数据实体模型 DbModel.edmx 需要跟数据库进行连 ...