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一个类型还有就是这道题的输出格式【如果有人能看我这个蒟蒻的题解的话……】六个一排,然后短的串在前面,长的串在后面,相同长度的串才是字典序
 1 /*
 2 ID: ivorysi
 3 PROG: contact
 4 LANG: C++
 5 */
 6 #include <iostream>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <algorithm>
10 #include <queue>
11 #include <set>
12 #include <vector>
13 #define siji(i,x,y) for(int i=(x);i<=(y);++i)
14 #define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
15 #define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
16 #define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
17 #define inf 0x7fffffff
18 #define MAXN 400005
19 #define ivorysi
20 #define mo 97797977
21 #define ha 974711
22 #define ba 47
23 #define fi first
24 #define se second
25 //#define pis pair<int,string>
26 using namespace std;
27 typedef long long ll;
28 int tree[100005];
29 string s;
30 int a,b,n;
31 struct pis {
32     int first;string second;
33 };
34 bool operator < (pis c,pis d) {
35     if(c.fi!=d.fi) return c.fi<d.fi;
36     else if(c.se.length()!=d.se.length()) return c.se.length() > d.se.length();
37     else return c.se > d.se;
38 }
39 priority_queue<pis> mq;
40 void dfs(int u,int t,string str){
41     if(t>b) return;
42     if(t>=a && tree[u]!=0) {
43         mq.push((pis){tree[u],str});
44     }
45     dfs(u<<1,t+1,str+"0");
46     dfs(u<<1|1,t+1,str+"1");
47 }
48 void solve() {
49     scanf("%d%d%d",&a,&b,&n);
50     string tm;
51     while(cin>>tm) s+=tm;
52     int t=s.length();
53     xiaosiji(i,0,t) {
54         int tmp=1;
55         int l=min(b,t-i);
56         xiaosiji(j,0,l) {
57             if(s[i+j]==‘0‘) tree[tmp<<=1]++;
58             else tree[tmp=(tmp<<1)+1]++;
59         }
60     }
61     dfs(1,0,"");
62     while(n>0) {
63         int cnt=0;
64         pis p=mq.top();mq.pop();
65         printf("%d\n%s",p.fi,p.se.c_str());
66         ++cnt;
67         if(mq.empty()) {puts("");break;}
68         while(mq.top().fi==p.fi) {
69             if(cnt==6) {puts("");cnt=0;}
70             else printf(" ");
71             printf("%s",mq.top().se.c_str());
72             mq.pop();
73             ++cnt;
74         }
75         puts("");
76         --n;
77     }
78 }
79 int main(int argc, char const *argv[])
80 {
81 #ifdef ivorysi
82     freopen("contact.in","r",stdin);
83     freopen("contact.out","w",stdout);
84 #else
85     freopen("f1.in","r",stdin);
86 #endif
87     solve();
88 }
 
时间: 2024-11-09 14:14:26

USACO 3.2 Contact的相关文章

USACO 3.1 Contact

http://www.nocow.cn/index.php/Translate:USACO/contact 题目大意:给一个只含0和1的序列,统计每个子序列的重复次数,并按次数递减来输出 考虑子序列时将序列前面加一个'1'然后转化成二进制整数,这样每个子序列与整数一一对应,统计二进制整数出现次数,按要求输出即可(ps:usaco老是喜欢在输出上做文章)代码如下(未提交): 1 /********************************************** 2 *** Proble

*usaco题目分享——Contact

ContactIOI'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

USACO Training Section 3.1 Contact

P2724 联系 Contact 题目背景 奶牛们开始对用射电望远镜扫描牧场外的宇宙感兴趣.最近,他们注意到了一种非常奇怪的脉冲调制微波从星系的中央发射出来.他们希望知道电波是否是被某些地外生命发射出来的,还是仅仅是普通的的星星发出的 题目描述 帮助奶牛们用一个能够分析他们在文件中记下的记录的工具来找到真相.他们在寻找长度在A到B之间(包含A和B本身)在每天的数据文件中重复得最多的比特序列 (1 <= A <= B <= 12).他们在找那些重复得最多的比特序列.一个输入限制告诉你应输出

USACO contact

题目意思是给你一个01串, 让你找出其中长度为A-B的串的频率, 输出频率最高的N个, 直接用map搞定, 代码如下: /* ID: m1500293 LANG: C++ PROG: contact */ #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <map> #include <iostream> #incl

【USACO 3.1.5】联系

[描述] 奶牛们开始对用射电望远镜扫描牧场外的宇宙感兴趣.最近,他们注意到了一种非常奇怪的脉冲调制微波从星系的中央发射出来.他们希望知道电波是否是被某些地外生命发射出来的,还是仅仅是普通的的星星发出的. 帮助奶牛们用一个能够分析他们在文件中记下的记录的工具来找到真相.他们在寻找长度在A到B之间(含)在每天的数据文件中重复得最多的比特序列 (1 <= A <= B <= 12).他们在找那些重复得最多的比特序列.一个输入限制告诉你应输出多少频率最多的序列. 符合的序列可能会重叠,并且至少出

洛谷 P3133 [USACO16JAN]无线电联系Radio Contact

P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan out and search the farm along different paths, but stay in contact via radio so they can keep in to

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

手动添加arraylist注解类(Contact联系人对象)

因为在Java核心库不支持arraylist xml直接注解,这里可以自己写个小工具类 Contact.java: package com.newer.xml; import java.util.ArrayList; import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; import org.simp

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>