*usaco题目分享——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 Binclusive (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

我是弱渣,我调试了好久(至少有两个小时)......全都是输出格式的错!!!!!!!其实,只需要一个个读入,再按题目要求做成字符串,还有一些基本字符串的操作。我们用到了sort神器和map神器。于是在解决了输出格式后,天都放晴了!
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int a,b,n,o;
map<string,int> k;
string g[10005];
int oo;
char s[200555];
struct like
{
    int ti;
    string xu;
    int len;
    int da;
    bool operator < (like l) const
    {
        if(ti==l.ti)
        {
            if(len==l.len) return da>l.da;
            else return len>l.len;
        }
        else return ti<l.ti;
    }
}f[100005];
int main()
{
    freopen("contact.in","r",stdin);
    freopen("contact.out","w",stdout);
    int i,j;
    scanf("%d%d%d",&a,&b,&n);
    char du;
    while(scanf("%c",&du)==1)
    {
        if(du!=‘0‘&&du!=‘1‘) continue;
        o++;
        s[o]=du;
        string z="";
        for(i=o;i>=o-b+1;--i)
        {
            string aa="";
            if(i<1) break;
            z+=s[i];
            if(z.length()<a||z.length()>b) continue;
            for(j=z.length()-1;j>=0;--j)
                aa+=z[j];
            if(k[aa]==0)
            {
                oo++;
                g[oo]=aa;
            }
            k[aa]++;
        }
    }
    for(i=1;i<=oo;++i)
    {
        f[i].ti=k[g[i]];
        f[i].len=g[i].length();
        int num=0;
        for(j=0;j<=g[i].length()-1;++j)
            num=num*2+g[i][j]-‘0‘;
        f[i].da=num;
        f[i].xu=g[i];
    }
    sort(f+1,f+1+oo);
    int p=0,awa=0;
    i=oo+1;
    int last=0,pp=0;
    while(p<=n)
    {
        i--;
        if(i<1) break;
        if(f[i].ti!=last)
        {
            last=f[i].ti;
            p++;
            if(p>n) break;
            if(awa>0&&pp!=1) printf("\n");
            awa++;
            printf("%d\n",last);
            pp=1;
        }
        if(pp==1)
        {
            cout<<f[i].xu;
        }
        else cout<<" "<<f[i].xu;
        pp++;
        if(pp==7)
        {
            pp=1;
            printf("\n");
        }
    }
    if(pp!=1) printf("\n");
    return 0;
}
时间: 2024-10-22 02:11:05

*usaco题目分享——Contact的相关文章

usaco题目分享——Longest Prefix

Longest PrefixIOI'96 The structure of some biological objects is represented by the sequence of their constituents, where each part is denoted by an uppercase letter. Biologists are interested in decomposing a long sequence into shorter sequences cal

usaco题目分享——Bessie Come Home

Bessie Come HomeKolstad & Burch It's dinner time, and the cows are out in their separate pastures. Farmer John rings the bell so they will start walking to the barn. Your job is to figure out which one cow gets to the barn first (the supplied test da

usaco题目分享——Controlling Companies

Controlling Companies Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford owns 12% of Mazda. It is said that a company A controls company B if at least one of the foll

usaco题目分享——Agri-Net

Agri-NetRuss Cox Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course. Farmer John ordered a high speed connection for his farm and is

USACO 3.1 Contact

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

模拟考试题目分享

1.多米诺骨牌(domino.pas) Jzabc对多米诺骨牌有很大的兴趣,然而他的骨牌比较特别,只有黑色的和白色的两种.他觉得如果存在连续三个骨牌是同一种颜色,那么这个骨牌排列便不是美观的.现在他有n个骨牌要来排列,他想知道不美观的排列个数.由于数字较大,数学不好的他又不会统计,所以他请你来帮忙.希望你在一秒内求出不美观的排列个数. [输入] 只有一个正整数,即要排列的骨牌个数. [输出] 一个数,即不美观的排列个数. [样例输入] 4 [样例输出] 6 [样例解释] 有四种不美观的排列. 黑

USACO 3.2 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

挖财 /有赞电话面试 题目分享

动画相关 //html <div class="btn"> <div class="change"></div> </div> //css .btn { width: 100px; height: 20px; background: coral; border: 1px solid #5e6d82; } .change { width: 0; height: 20px; background: #2D93CA; tra

金朝阳——软件测试试题11道题目分享

测试人员相对于开发人员来说,对知识的广度要求更高. 1:下面所描述的属于安全漏洞方面的有哪些?()A.SQL注入问题B.跨站脚本(XSS)C.不安全的加密存储,比如CSDN网站的用户密码是明文密码D.网站访问缓慢 2:关于Loadrunner下列说法正确的是()A.web_reg_save_param最常用來做关联的函数B. 函数lr_save_string("我是一名软件测试工程师","tester")的含义是"把我是一名软件测试工程师字符串赋了test