首页 > 其他分享 >统计难题 HDU - 1251

统计难题 HDU - 1251

时间:2023-02-26 17:11:47浏览次数:39  
标签:难题 HDU int len char num 1251 include

 

给一些字符串,问以某个串为前缀的串有几个

 

#include<iostream>
#include <algorithm>
#include <cstring>
using namespace std;
 const int N=5e5+4;
 char num[80];
 int len,sum[N];
 int ch[N][30],tot;
 
 int find(char *s){
 	int i,u=1;
 	
 	for(i=0;i<len;i++){
         int c=s[i]-'a';
         if(ch[u][c]==0){
             return 0;
         }
         u=ch[u][c];
     }
     return sum[u];
 }
 void insert(char *s){
     int i,u=1;
     
     for(i=0;i<len;i++){
         int c=s[i]-'a';
         if(ch[u][c]==0){
             ch[u][c]=++tot; 
         }
         u=ch[u][c];
         sum[u]++;
     }
 }
 
 int main(){
     tot=1; 
         memset(ch,0,sizeof ch);
         
      while(gets(num),strlen(num)>0){
          len=strlen(num); insert(num);
      }
      while(gets(num)){
          len=strlen(num); cout<<find(num)<<'\n';
      }
 }

 

标签:难题,HDU,int,len,char,num,1251,include
From: https://www.cnblogs.com/towboa/p/17157065.html

相关文章

  • Reading comprehension HDU - 4990
    ans=0;   for(i=1;i<=n;i++)    {     if(i&1)ans=(ans*2+1)%m;     elseans=ans*2%m;    } ......
  • P1379 八数码难题 题解
    IDA*练习题由于题目问最小步数,很好想到可以用迭代式加深搜索,或是广搜,这里用的是深搜。枚举每次搜索的深度,也就是移动的步数,然后正常深搜,若达到目标解,返回\(\text{ture}......
  • HDU 4081 Qin Shi Huang's National Road System(次小树,4级)
    A- QinShiHuang'sNationalRoadSystemTimeLimit:1000MS     MemoryLimit:32768KB     64bitIOFormat:%I64d&%I64uSubmit ​​Status​​......
  • hdu 4284 Travel(压缩DP,4级)
    TravelTimeLimit:10000/5000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):2641    AcceptedSubmission(s):724......
  • hdu 2608 0 or 1(数论)
    0or1TimeLimit:6000/2000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):1659    AcceptedSubmission(s):418Pro......
  • HDU 2888 Check Corners (二维RMQ,3级)
    A-CheckCornersCrawlinginprocess...CrawlingfailedTimeLimit:10000MS    MemoryLimit:32768KB    64bitIOFormat:%I64d&%I64u​​Submit......
  • HDUOJ 2000-2100
    2024C语言合法标识符ProblemDescription输入一个字符串,判断其是否是C的合法标识符。 Input输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然......
  • DUTOJ-1018: totoday的难题
    一共三种情况白(-2)=>黑(+1)最终白(-2)黑(+1)白(-1)黑(-1)=>白(+1)最终黑(-1)黑(-2)=>黑(+1)最终黑(-1)可以看出白球只能是每次减少2最后剩余一个球,那么白球是最开始是奇数最后......
  • 工业物联网网关为煤炭矿山解决设备通信和隐患排查难题
    工业物联网网关作为物联网技术在工业领域的应用产品,是工业生产加速升效的助推力之一。它是将具有感知、生产、控制能力的传感器、PLC、机床等设备数据采集起来,实现设备通信......
  • [hdu 5307] He is Flying (FFT)
    题意给出长度为的数列,对于任意,求出区间和为的区间的长度之和题目分析有了几道fft题的经验,套路就是把可加性的计算化为幂的次数做多项式卷积有分别把看成两个多项式,做FF......