usaco3.1 contact

题目链接


题意:

给一个01串s,统计其中长度从A到B的各个子串出现的次数,输出频率最高的N个


十分朴素且无脑地过了...还很快

对于A到B的每个长度len,取出s中所有该长度的串,转化为二进制x,++cnt[len][x],

再作为node放到ans数组中,node有三个成员,val, len, cnt(值,长度,出现次数)

对ans排序,再输出即可

再就是,输入输出稍微注意一点


AC代码如下:

/*
PROB:contact
LANG:C++
ID:fan_0111
*/
#include <cstdio>
#include <algorithm>
struct node { int len, cnt, val; }ans[10010];
bool cmp(node a, node b) {
    if (a.cnt == b.cnt) {
        if (a.len == b.len) return a.val < b.val;
        return a.len < b.len;
    }
    return a.cnt > b.cnt;
}
int cnt[13][10010];
char ch[200020];
void print(int len, int x) {
//    printf("\n%d %d\n", len, x);
    char ret[len + 1] = "";
    ret[len] = '\0';
    int i = len - 1;
    while (x) {
        ret[i--] = x % 2 + '0';
        x /= 2;
    }
    for (int j = i; j >= 0; --j) ret[j] = '0';
    printf("%s", ret);
}
using namespace std;
int main() {
    freopen("contact.in", "r", stdin);
    freopen("contact.out", "w", stdout);
    int a, b, n;
    scanf("%d%d%d\n", &a, &b, &n);
    int len = 0;
    while (scanf("%c", &ch[len]) != EOF) {
        if (ch[len] == '\n') continue;
        ++len;
    }
    b = len < b ? len : b;
//    printf("%c\n", ch[0]);
//    printf("%d
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值