KMP

// hdu 1358前缀是由几个循环串组成  next数组的运用  next[i]数组是后缀与前缀的最大相匹配的字符个数

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
#define inf 0x3f3f3f3f
#define eps 1e-10
#define maxl 1000010
#define mem(i,j) memset(i,j,sizeof(i))
const int mod=1e9+7;
char s[maxl];
int n,jump[maxl];
void get_next(){
    jump[1]=0;
    int k=0;
    for(int i=2;i<=n;i++){
        while(k>0&&s[k+1]!=s[i]) k=jump[k];
        if(s[k+1]==s[i]) k+=1;
        jump[i]=k;
    }
}

int main()
{
    freopen("in.txt", "r", stdin);
    int t=0;
    while(scanf("%d",&n)&&n){
        printf("Test case #%d\n",++t);
        scanf("%s",s+1);
        get_next();    
        for(int i=2;i<=n;i++){
            if(jump[i]&&i%(i-jump[i])==0){
                printf("%d %d\n",i,i/(i-jump[i]));
            }
        }
        printf("\n");
    }
}





//P UVA 11475   补全字符串  使得这个是回文字符串  但是补的字符最少   这是暴力的做法  KMP的还有待学习
/*
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
#define inf 0x3f3f3f3f
#define eps 1e-10
#define maxl 1000010
#define mem(i,j) memset(i,j,sizeof(i))
const int mod=1e9+7;
char s[maxl];
int main()
{
    freopen("in.txt", "r", stdin);
    while(gets(s)){
        int len=strlen(s);
        for(int i=0;i<len;i++){
            int l=i,r=len-1;
            int flag=1;
            for(int j=0;j<=(r-l+1)/2;j++) if(s[l+j]!=s[r-j]) {flag=0;break;}
            if(flag){
                printf("%s",s);
                for(int j=i-1;j>=0;j--) printf("%c",s[j]);
                printf("\n");
                break;
            }
        }
    }
}
*/

//O UVA 12886二维的KMP  但是只有黑白俩种  hash   小矩形和大矩形 <=2000  hash打法 可以处理的情况很大的时候

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef unsigned long long ll;  
typedef pair<int,int> pp;
#define inf 0x3f3f3f3f
#define eps 1e-10
#define maxl 2020
#define mem(i,j) memset(i,j,sizeof(i))
const int mod=1e9+7;
const ll seed1=10000007;
const ll seed2=100000007;
char s1[maxl][maxl],s2[maxl][maxl];
ll hash1[maxl][maxl],hash2[maxl][maxl],h;
int x,y,n,m,ans;
ll get_hash(){  //预处理小矩形
    ll cnt=0,res;
    for(int i=0;i<x;i++){
        res=0;
        for(int j=0;j<y;j++)
            res=res*seed1+s1[i][j];//处理行
        cnt=cnt*seed2+res;//处理列
    }
    return cnt;
}

void solve(){
    ans=0;
    ll c=1;
    for(int i=0;i<y;i++) c=c*seed1;//这个是hash种子   y次seed1
    for(int i=0;i<n;i++){
        ll res=0;
        for(int j=0;j<y;j++) //这里的0是y-1次seed1 刚好对应下面的
            res=res*seed1+s2[i][j];//处理相同长度的目标矩形的行
        hash1[i][y-1]=res;//用hash1来保存
        for(int j=y;j<m;j++){
            hash1[i][j]=hash1[i][j-1]*seed1-s2[i][j-y]*c+s2[i][j];//用DP的思想 来递归
        }
    }
    c=1;
    for(int i=0;i<x;i++) c=c*seed2;
    for(int i=y-1;i<m;i++){
        ll cnt=0;
        for(int j=0;j<x;j++)
            cnt=cnt*seed2+hash1[j][i];
        if(cnt==h) ans++;
        hash2[x-1][i]=cnt;
        for(int j=x;j<n;j++){
            hash2[j][i]=hash2[j-1][i]*seed2-hash1[j-x][i]*c+hash1[j][i];
            if(hash2[j][i]==h) ans++;
        }
    }
}

int main()
{
    freopen("in.txt", "r", stdin);
    while(scanf("%d%d%d%d",&x,&y,&n,&m)!=EOF){
        memset(hash1,0,sizeof(hash1));
        memset(hash2,0,sizeof(hash2));
        for(int i=0;i<x;i++) scanf("%s",s1[i]);
        for(int i=0;i<n;i++) scanf("%s",s2[i]);
        h=get_hash();
        solve();
        printf("%d\n",ans);
    }
}



内容概要:2025年大宗商品市场展望报告由世界银行发布,分析了能源、农业、金属和矿物、贵金属以及化肥等多个主要商品类别的市场发展与前景。报告指出,由于全球经济增长放缓和贸易紧张加剧,2025年大宗商品价格预计总体下降12%,2026年进一步下降5%,达到六年来的最低点。油价预计2025年平均为每桶64美元,2026年降至60美元,主要受全球石油消费放缓和供应增加的影响。农业商品价格预计2025年基本稳定,2026年下降3%,其中粮食和原材料价格分别下降7%和2%,但饮料价格上涨20%。金属价格预计2025年下降10%,2026年再降3%,特别是铜和铝价格将显著下跌。贵金属如黄金和白银因避险需求强劲,预计价格将继续上涨。报告还特别关注了疫情后大宗商品周期的变化,指出周期变得更短、更剧烈,主要受到宏观经济冲击、极端天气事件和地缘政治冲突的影响。 适用人群:对全球经济趋势、大宗商品市场动态及其对不同经济体影响感兴趣的政策制定者、投资者、分析师及研究机构。 使用场景及目标:①帮助政策制定者评估全球经济增长放缓对大宗商品市场的影响,从而调整经济政策;②为投资者提供有关未来大宗商品价格走势的风险提示,以便进行投资决策;③协助分析师和研究机构深入理解疫情后大宗商品市场的周期特征,识别潜在的投资机会和风险。 其他说明:报告强调,全球经济增长放缓、贸易紧张加剧以及地缘政治不确定性是影响大宗商品价格的主要因素。此外,极端天气事件和能源转型也对农业和能源商品市场产生了深远影响。报告呼吁各方关注这些结构性变化,并采取相应的风险管理措施。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值