Good Article Good sentence

40 篇文章 0 订阅
28 篇文章 9 订阅

题目描述

In middle school, teachers used to encourage us to pick up pretty sentences so that we could apply those sentences in our own articles. One of my classmates ZengXiao Xian, wanted to get sentences which are different from that of others, because he thought the distinct pretty sentences might benefit him a lot to get a high score in his article. 
Assume that all of the sentences came from some articles. ZengXiao Xian intended to pick from Article A. The number of his classmates is n. The i-th classmate picked from Article Bi. Now ZengXiao Xian wants to know how many different sentences she could pick from Article A which don't belong to either of her classmates?Article. To simplify the problem, ZengXiao Xian wants to know how many different strings, which is the substring of string A, but is not substring of either of string Bi. Of course, you will help him, won't you? 

输入描述:

The first line contains an integer T, the number of test data. 
       
For each test data 
The first line contains an integer meaning the number of classmates.
       
The second line is the string A;The next n lines,the ith line input string Bi.
       
The length of the string A does not exceed 100,000 characters , The sum of total length of all strings Bi does not exceed 100,000, and assume all string consist only lowercase characters 'a' to 'z'.
       

输出描述:

For each case, print the case number and the number of substrings that ZengXiao Xian can find.
示例1

输入

3
2
abab
ab
ba
1
aaa
bbb
2
aaaa
aa
aaa

输出

Case 1: 3
Case 2: 3
Case 3: 1
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<queue>
#define inf 1<<28
#define M 6000005
#define N 1000005
#define maxn 300005
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define pb(a) push_back(a)
#define mem(a,b) memset(a,b,sizeof(a))
#define LL long long
#define MOD 1000000007
using namespace std;
int wa[maxn],wb[maxn],wv[maxn],Ws[maxn]; 
int cmp(int *r,int a,int b,int l) 
{return r[a]==r[b]&&r[a+l]==r[b+l];} 
void da(const int *r,int *sa,int n,int m){ 
    int i,j,p,*x=wa,*y=wb,*t;  
    for(i=0;i<m;i++) Ws[i]=0;  
    for(i=0;i<n;i++) Ws[x[i]=r[i]]++;  
    for(i=1;i<m;i++) Ws[i]+=Ws[i-1];  
    for(i=n-1;i>=0;i--) sa[--Ws[x[i]]]=i;  
    for(j=1,p=1;p<n;j*=2,m=p){  
        for(p=0,i=n-j;i<n;i++) y[p++]=i;  
        for(i=0;i<n;i++) if(sa[i]>=j) y[p++]=sa[i]-j;  
        for(i=0;i<n;i++) wv[i]=x[y[i]];  
        for(i=0;i<m;i++) Ws[i]=0;  
        for(i=0;i<n;i++) Ws[wv[i]]++;  
        for(i=1;i<m;i++) Ws[i]+=Ws[i-1];  
        for(i=n-1;i>=0;i--) sa[--Ws[wv[i]]]=y[i];  
        for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1;i<n;i++)  
            x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;  
    }  
    return;  
} 
int sa[maxn],Rank[maxn],height[maxn]; 
void calheight(const int *r,int *sa,int n){ 
    int i,j,k=0; 
    for(i=1;i<=n;i++) Rank[sa[i]]=i; 
    for(i=0;i<n;height[Rank[i++]]=k) 
        for(k?k--:0,j=sa[Rank[i]-1];r[i+k]==r[j+k];k++); 
    return; 
}
int a[maxn],pos[maxn];
char str[maxn];
int main(){
    int t,cas=0,n;
    scanf("%d",&t);
    while(t--){
        int len,m=0,num=30;
        scanf("%d",&n);
        scanf("%s",str);
        len=strlen(str);
        for(int i=0;i<len;i++) a[m++]=str[i]-'a'+1;
        for(int i=0;i<n;i++){
            a[m++]=num++;
            scanf("%s",str);
            int l=strlen(str);
            for(int j=0;j<l;j++)
                a[m++]=str[j]-'a'+1;
        }
        a[m]=0;
        da(a,sa,m+1,num+1);
        calheight(a,sa,m);
        mem(pos,0);
        int tmp=inf;
        for(int i=1;i<=m;i++){
            if(sa[i]<len){
                if(height[i]<tmp) tmp=height[i];
                if(pos[sa[i]]<tmp) pos[sa[i]]=tmp;
            }
            else tmp=inf;
        }
        tmp=inf;
        for(int i=m;i>=1;i--){
            if(sa[i-1]<len){
                if(height[i]<tmp) tmp=height[i];
                if(pos[sa[i-1]]<tmp) pos[sa[i-1]]=tmp;
            }
            else tmp=inf;
        }
        for(int i=1;i<=m;i++)
             if(sa[i]<len&& sa[i-1]<len)
                if(pos[sa[i-1]]<height[i]) 
                    pos[sa[i-1]]=height[i]; 
        LL ans=(LL)len*(len+1)/2;
        for(int i=0;i<len;i++)
            ans-=pos[i];
        printf("Case %d: %I64d\n",++cas,ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sentence Transformer是一个Python框架,用于生成句子、文本和图像的嵌入(Embedding)表示。通过使用该框架,可以将文本转化为向量表示,从而在文本相似度计算、文本分类等任务中使用。这个框架使用了预训练的语言模型,例如MiniLM等,来生成高质量的文本嵌入,以捕捉句子的语义信息。 使用Sentence Transformer的过程是比较简单的。首先,需要导入框架并加载相应的模型。然后,将待处理的句子作为一个字符串列表传入模型的encode方法中,即可获取到对应的嵌入向量。最后,可以根据需要对这些嵌入向量进行进一步的处理和应用。 通过使用Sentence Transformer,我们可以方便地将文本转化为向量表示,并在各种NLP任务中发挥作用,比如文本相似度计算、文本分类、信息检索等。这个框架提供了一种简单而有效的方式来处理文本数据,并获得具有丰富语义信息的嵌入表示。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [SentenceTransformers库介绍](https://blog.csdn.net/m0_47256162/article/details/129380499)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [5分钟 NLP系列 — SentenceTransformers 库介绍](https://blog.csdn.net/m0_46510245/article/details/122516399)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值