USACO section 3.1 Contact(AC自动机)

hcaptcha无感验证码逆向实战:从接口分析到环境补全 本文详细解析了hcaptcha无感验证码的逆向实战过程。通过分析核心接口与加密逻辑,重点介绍了采用环境补全策略来模拟真实浏览器环境,从而绕过验证码检测。文章提供了从接口抓包、剖析hsw.js加密核心到使用Node.js搭建模拟环境的完整步骤,为自动化操作提供了一种稳健的解决方案。 阅读详情
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 lengthA 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


 

思路:用AC自动机匹配所有字串的个数,然后拍序,按要求输出。自动机里的插入用深搜枚举题目要求的长度。

           然后匹配,在深搜一遍吧结果存到类数组中,排序输出即可。

失误点:原先居然用KMP,毫无疑问死了,很坑人的是此题中有不够的输出就结束,并且个数0的不输出,结果WA了一次

效率还是很好的,

   Test 1: TEST OK [0.000 secs, 3888 KB]

   Test 2: TEST OK [0.000 secs, 3888 KB]

   Test 3: TEST OK [0.032 secs, 4020 KB]

   Test 4: TEST OK [0.000 secs, 3888 KB]

   Test 5: TEST OK [0.065 secs, 4020 KB]

   Test 6: TEST OK [0.097 secs, 3888 KB]

   Test 7: TEST OK [0.162 secs, 4020 KB]

All tests OK.

 

具体看代码:

 

 

/*
ID:nealgav1
LANG:C++
PROG:contact
*/
#include<fstream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
ifstream cin("contact.in");
ofstream cout("contact.out");
char s[201000];
const int mm=16384;///最大的个数
class node
{public:
  node*fail;
  node*next[2];
  int num;
  node(){fail=NULL;memset(next,NULL,sizeof(next));num=0;}
};
class AC
{
  public:
  char s[14];
  int num;
}ans[mm];
int pos;
int _min,_max;
/**
void insert(node*root,int len)
{  node*p=root;
  for(int i=0;i<len;i++)
  {
    int index=0;
    if(p->next[index]==NULL)
    p->next[index]=new node();
    p=p->next[index];i++;
  }
  p->num++;
}*/
/**使用深搜插入所有可能的情况,其实就是建个字典树啦*/
void insert(node*root,int num,int dep)
{
  node*p=root;
  if(dep>_max)return;
  if(p->next[num]==NULL)
  p->next[num]=new node();
  //if(dep>=_min)p->num++;
  insert(p->next[num],0,dep+1);
  insert(p->next[num],1,dep+1);
}
///构造失败指针
void AC_anto(node*root)
{
  node*temp,*p;
  root->fail=NULL;
  queue<node*>Q;
  Q.push(root);
  while(!Q.empty())
  {
    temp=Q.front();Q.pop();
    for(int i=0;i<2;i++)
    {
      if(temp->next[i]!=NULL)
      {
        p=temp->fail;
        while(p!=NULL)
        {
          if(p->next[i]!=NULL)
          {
            temp->next[i]->fail=p->next[i];break;
          }p=p->fail;
        }
        if(p==NULL)
        temp->next[i]->fail=root;
        Q.push(temp->next[i]);
      }
    }
  }
}
///算出所有匹配情况的个数
int query(node*root,char s[])
{ AC_anto(root);
  int i=0;
  int cnt=0;
  node*p=root;
  while(s[i]!='\0')
  {
    int index=s[i]-'0';
    while(p->next[index]==NULL&&p!=root)
    p=p->fail;
    p=p->next[index];
    if(p==NULL)p=root;
    node*temp=p;
    while(temp!=root)
    {
      temp->num++;
      temp=temp->fail;
    }
    i++;
  }
  return cnt;
}
///从字典树中转化为类数组
void _data(node*root,int num,int dep)
{
  node*p=root;
  s[dep-1]=num+'0';
  //if(p->next[num]==NULL)
  //p->next[num]=new node();
  if(dep>_max)return;

  if(dep>=_min)
  {
   //cout<<p->next[num]->num<<"\n";
   s[dep]='\0';
   //cout<<s<<"\n";
   ///为什么是p->next[num]->num?不解释
   ans[pos].num=p->next[num]->num;
   strcpy(ans[pos].s,s);
   pos++;
  }
  _data(p->next[num],0,dep+1);
  _data(p->next[num],1,dep+1);
}
bool cmp(AC a,AC b)
{ if(a.num==b.num)
  { int c=strlen(a.s),d=strlen(b.s);
    if(c==d)
    return strcmp(a.s,b.s)<0;
    else return c<d;
  }
  return a.num>b.num;
}
int main()
{ int m;
  cin>>_min>>_max>>m;
  char kk[88];
  int lens=0;
  while(cin>>kk)
  {
    strcpy(s+lens,kk);
    lens=strlen(s);
  }
  pos=0;
  node*root=new node();
  insert(root,0,1);insert(root,1,1);
  query(root,s);
  _data(root,0,1);_data(root,1,1);
  sort(ans,ans+pos,cmp);
  cout<<ans[0].num<<"\n"<<ans[0].s;
  int len=0;
  int past=1;///每行保证输出6个
  for(int i=1;i<pos&&ans[i].num/**个数需要大于0才能输出*/;i++)
  {
    if(ans[i].num==ans[i-1].num)
    { if(past%6==0)cout<<"\n"<<ans[i].s;
      else
      cout<<" "<<ans[i].s;
      ++past;
    }
    else
    { ++len;if(len==m)break;
      cout<<"\n"<<ans[i].num<<"\n"<<ans[i].s;past=1;
    }

  }
  cout<<"\n";
}


 

Contact
Russ Cox

For this problem, we keep track of every bit sequence we see. We could use the bit sequence itself as an index into a table of frequencies, but that would not distinguish between the 2-bit sequence "10" and the 4-bit sequence "0010". To solve this, we always add a 1 to the beginning of the number, so "10" becomes "110" and "0010" becomes "10010".

After reading the entire bit string, we sort the frequency table and walk through it to print out the top sequences.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#define MAXBITS 12
#define MAXSEQ (1<<(MAXBITS+1))

typedef struct Seq Seq;
struct Seq {
    unsigned bits;
    int count;
};

Seq seq[MAXSEQ];

/* increment the count for the n-bit sequence "bits" */
void
addseq(unsigned bits, int n)
{
    bits &= (1<<n)-1;
    bits |= 1<<n;
    assert(seq[bits].bits == bits);
    seq[bits].count++;
}

/* print the bit sequence, decoding the 1<<n stuff */
/* recurse to print the bits most significant bit first */
void
printbits(FILE *fout, unsigned bits)
{
    assert(bits >= 1);
    if(bits == 1)	/* zero-bit sequence */
	return;

    printbits(fout, bits>>1);
    fprintf(fout, "%d", bits&1);
}

int
seqcmp(const void *va, const void *vb)
{
    Seq *a, *b;

    a = (Seq*)va;
    b = (Seq*)vb;

    /* big counts first */
    if(a->count < b->count)
	return 1;
    if(a->count > b->count)
	return -1;

    /* same count: small numbers first */
    if(a->bits < b->bits)
	return -1;
    if(a->bits > b->bits)
	return 1;

    return 0;
}

void
main(void)
{
    FILE *fin, *fout;
    int i, a, b, n, nbit, c, j, k;
    unsigned bit;
    char *sep;

    fin = fopen("contact.in", "r");
    fout = fopen("contact.out", "w");
    assert(fin != NULL && fout != NULL);

    nbit = 0;
    bit = 0;

    for(i=0; i<=MAXBITS; i++)
	for(j=0; j<(1<<i); j++)
	    seq[(1<<i) | j].bits = (1<<i) | j;

    fscanf(fin, "%d %d %d", &a, &b, &n);

    while((c = getc(fin)) != EOF) {
	if(c != '0' && c != '1')
	    continue;

	bit <<= 1;
	if(c == '1')
	    bit |= 1;

	if(nbit < b)
	    nbit++;

	for(i=a; i<=nbit; i++)
	    addseq(bit, i);
    }

    qsort(seq, MAXSEQ, sizeof(Seq), seqcmp);

    /* print top n frequencies for number of bits between a and b */
    j = 0;
    for(i=0; i<n && j < MAXSEQ; i++) {
	if(seq[j].count == 0)
	    break;

	c = seq[j].count;
	fprintf(fout, "%d\n", c);

	/* print all entries with frequency c */
	sep = "";
	for(k=0; seq[j].count == c; j++, k++) {
	    fprintf(fout, sep);
	    printbits(fout, seq[j].bits);
	    if(k%6 == 5)
		sep = "\n";
	    else
		sep = " ";
	}
	fprintf(fout, "\n");
    }

    exit(0);
}


 

 

 

 

 

 

为什么你的Mac蓝牙总断连?深入解析硬件干扰与系统设置避坑 本文深入解析Mac蓝牙频繁断连的原因,包括硬件干扰(如WiFi同频干扰、USB设备电磁干扰)和系统设置问题,并提供详细的优化方案和诊断工具(如blueutil)使用指南,帮助用户有效解决蓝牙稳定性问题。 阅读详情

相关推荐

【CVPR 2025】低光增强HVI论文精读与源码复现---part1 论文网络精读

【CVPR 2025】本文参考论文HVI: A New Color Space for Low-light Image Enhancement part1 在文章中对论文核心网络与原理展开详细解释 part2 对论文公开代码的arch网络与其他核心部分展开详细解释

BOB_BOB_BOB_的博客 3291

洛谷 P3041 [USACO12JAN]Video Game G(AC自动机+DP)

题目不难想到要应用 DP,建好 AC自动机之后 dp[i][j] 表示到第i 个字符标号为j 的节点时最大的连击数是多少 dp 方程也不难想 由于本人实力欠缺,dp 数组的初始化为什么要设为 -1 没想明白,先给自己挖个坑 QAQ const int N=300+5; int n,m; int i,j,k; char s[N]; int t[N][3],tot=0; int vis[N],f[N]; int dp[(int)1e3+5...

C_Dreamy的博客 504

手把手解决GD32H759I-EVAL以太网通信三大坑:IP冲突、端口绑定失败、LWIP内存泄漏

本文针对GD32H759I-EVAL开发板在以太网通信调试中常见的三大难题——IP地址冲突、端口绑定失败和LWIP内存泄漏,提供了详细的实战排障指南。文章深入分析了问题根源,并给出了具体的网络配置、端口管理策略和内存泄漏检测方法,帮助开发者快速定位并解决嵌入式网络通信中的棘手问题,确保系统稳定运行。

weixin_29196315的博客 149

【USACO】AC自动机

Description 对,这就是裸的AC自动机。要求:在规定时间内统计出模版字符串在文本中出现的次数。 Input 第一行:模版字符串的个数N。第2->N+1行:N个字符串。(每个模版字符串的长度<=50)第N+2行:一行很长的字符串。长的很。(使用AC自动机能在1s内计算出) ...

weixin_30273763的博客 138

CST仿真提速秘籍:用好Local Mesh,别再让简单结构拖慢你的仿真速度

本文深入探讨了CST仿真中Local Mesh技术的应用,通过区域加密与全局排除策略,显著提升电磁仿真效率。针对5G天线阵列、微波滤波器等多尺度结构模型,提供了网格划分的黄金法则和实战技巧,帮助工程师优化仿真速度与精度,特别适用于电磁仿真和网格设置场景。

weixin_27134495的博客 415

【AI+教育】别再让 Cursor 只当编辑器了!4 步解锁 Claude 官方技能!

本文介绍了在Windows环境下通过OpenSkills工具在Cursor中调用Claude AI技能的方法。主要内容包括:1)安装Node.js环境;2)全局安装OpenSkills工具;3)安装Claude官方技能库;4)通过AGENTS.md文件同步技能;5)在Cursor中直接调用技能完成Excel、PPT等任务。文章提供了详细的操作步骤和示例,帮助用户快速上手使用AI技能提升工作效率。

奶爸的编程之路,也就一周冷个三天 762

3.1.5 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...

weixin_30725467的博客 1607

机器学习实战26-一种基于LightGBM的股市涨跌预测系统与代码实现过程

在全球经济一体化的背景下,股市作为经济活动的晴雨表,其波动与预测对于投资者、金融机构乃至国家政策制定者而言至关重要。随着金融市场的日益复杂化与信息量的爆炸式增长,股市分析不再仅限于基本面和技术面的传统研究,而是迫切需要更加精准、高效及智能化的方法来捕捉市场动态,以辅助决策制定。模型评估是确保LightGBM股市预测系统准确性和稳定性不可或缺的一环。通过综合运用多种评估指标、科学的验证方法以及深入的性能分析,我们不仅能够全面理解模型的能力和限制,还能为持续优化模型、提升预测准确性奠定坚实基础。

微学AI的博客 2338

USACO Section 3.1 Contact - AC自动机..

赤果果的AC自动机~并且比较阉割~比完整的AC自动机好写多了..  首先构造一个完全二叉树..根据题目要求构造13层..根节点为1,根的左孩子为2,右孩子为3..依次类推..那么一个节点P的父亲为P/2...左孩子为P*2...右孩子为P*2+1..所以整棵树用一维数组来存就okl了...这棵树转化为字典数..可以看成..1是超级节点..2是'0'...3是'1'..4是'00'..5是...

huobengle 336

AI大模型探索之路-认知篇1-全景透视:揭秘AIGC技术的进化之路

随着人工智能技术的突飞猛进,内容创作方式的发生了革命性的转变;从早期专业人员主导的内容生产,到现如今生成式人工智(AIGC)能创作时代;本篇文章主要讲解AIGC技术的演变历程。

寻道AI,探索AI无限可能! 1662

redhawk:上电分析报告“rampup has not been completed”如何解决

工具报告“rampup has not been completed,please check your settings”,意思是上电未完成,用户设置的仿真时间太短了,所以需要调整这个仿真时间,但增加时间又会影响runtime,所以需要调整step值。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 1125

USACO题解——Section 1.2——Greedy Gift Givers

题目地址:https://train.usaco.org/usacoprob2?a=BGOMbIJsisd&S=gift1。 或者我的OJ网站,http://47.110.135.197/problem.php?id=5184。 题目 A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange ...

努力中的老周的专栏 7657

详解Xilinx FPGA高速串行收发器GTX/GTP(1)--SerDes和GTX的关系

详解Xilinx FPGA高速串行收发器GTX/GTP(1)--SerDes和GTX的关系

孤独的单刀 4368

[USACO Training] Section 1.4

这一章的主题是枚举。 搜索 时间 空间 何时使用 DFS O(c^k) O(k) 必须搜索整棵树,知道解所在的层数,或者不需要层次最浅的解 BFS O(c^d) O(c^d) 知道解所在的层次很浅,或者需要最浅的解 DFS+ID O(c^d) O(d) 想要BFS,却没有足够的空间,并且能承受以时间换空间 c是每层做出的选择的数目 d是解的深度 k是搜索的深度 d <= k

chrt's blog 832

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

USACO Training Section 1.3 Calf Flac 解题报告&AC代码

解题报告: 主要方法是生长法,考虑每一位的左右各有多长的回文串,输出最长的那个,比较好想……不过要注意区分字串的奇偶。 其他实现细节看代码里的注释吧…… AC代码: /* ID: yuanmz91 PROG: calfflac LANG: C++ */ #include #include #include using namespace std; const int MAX_LEN

堆放杂物 6825

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

USACO section 1.1 C++题解

USACO section1.1题解

箜瑟_qi的博客 1298

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

USACO题解——Section 1.2——Your Ride Is Here

题目地址:https://train.usaco.org/usacoprob2?a=g6aKKOrpotS&S=ride。估计这个网页需要登录才能看到。 我自己的OJ上题目链接是http://47.110.135.197/problem.php?id=4362。 题意 就是输入两个不超过 6 长度的全部由大写字符构成字符串,然后按照某种规定(A变1,B变2,...,Z变26),计算两...

努力中的老周的专栏 7533

P1208 [USACO1.3] 混合牛奶 Mixing Milk【贪心】

由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要。帮助 Marry 乳业找到最优的牛奶采购方案。Marry 乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格可能相同。此外,就像每头奶牛每天只能挤出固定数量的奶,每位奶农每天能提供的牛奶数量是一定的。每天 Marry 乳业可以从奶农手中采购到小于或者等于奶农最大产量的整数数量的牛奶。给出 Marry 乳业每天对牛奶的需求量,还有每位奶农提供的牛奶单价和产量。计算采购足够数量的牛奶所需的最小花费。

海岛Blog 703

USACO section 1.5.3 SuperPrime Rib

USACO section 1.5.3 SuperPrime Rib 1. 从数学的角度: 1.首位只能是质数2 3 5 7 2.其余位只能是1,3,7,9 3.若n=1,直接输出2,3,5 7 直接DFS 1~9,加入当前数末尾,并判断是不是素数,是则递归...

dayong9372的博客 176

USACO Training Section 1.2 [USACO1.2]方块转换 Transformations

题目描述 一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案。写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式: 1:转90度:图案按顺时针转90度。 2:转180度:图案按顺时针转180度。 3:转270度:图案按顺时针转270度。 4:反射:图案在水平方向翻转(以中央铅垂线为中心形成原图案的镜像)。 5:组合:图案在水平方向翻转,然后...

日拱一卒,功不唐捐 2850

USACO 之 Section 1.1 Ad Hoc Problems

Your Ride Is Here

JmingS 752

USACO题解——Section 1.2——Friday the Thirteenth

题目地址:https://train.usaco.org/usacoprob2?a=ddY7pfROLpX&S=friday。 或者我的OJ,http://47.110.135.197/problem.php?id=5185。 题目 Is Friday the 13th really an unusual event? That is, does the 13th of the m...

努力中的老周的专栏 7805

USACO-Section 3.1 Stamps(DP)

这种简单的dp直接能想到做法 提交的代码没有判断i<2000003也AC,没有越界,不过感觉这样更严谨

idealism_xxm的专栏 569

洛谷 P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少。在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。给出一群朋友,没有人的名字会长于 14 字符,给出每个人将花在送礼上的钱,和将收到他的礼物的人的列表,请确定每个...

anshuo0835的博客 291

Usaco Training Section 1.6 Superprime Rib

让你求n位数中的超级素数(sp)。(如7331,7331、733、73、7都是素数,7331就是sp) 这题我写了三个版本。第一个版本是线性筛,求出所有素数,判断前缀是否为素数。但打完自测时发现会超时,换了第二个版本。第二个版本就是暴力。暴力枚举所有n位数,再判断。打了一半突然想到第三种做法。因为sp有一个性质:一个sp的前缀肯定也是sp。于是我们可以用构造的方法。一位的sp只有2,3,5,7。...

Monster的博客 318

USACO Section1.5 Prime Palindromes 解题报告

    pprime解题报告—— icedream61 博客园(转载请注明出处)------------------------------------------------------------------------------------------------------------------------------------------------【题目】   求a到b之间的...

weixin_30794491的博客 139
上一篇: USACO section 3.1 Stamps(dp)
下一篇: USACO section 3.2 Factorials(dp)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址