[Learning] SAM

From cxlove

资料

http://fanhq666.blog.163.com/blog/static/8194342620123352232937/

题目

http://www.spoj.pl/problems/NSUBSTR/ 

这题基本上就是套个木板T_T 。 借鉴的cxlove 和 UESTC 神奇的 后缀三兄弟 Orz 

cxlove mua ~

const int N = 250009;
namespace SAM{
const int CHAR = 26;
const int LEN = N << 1;
struct SAM_Node{
    SAM_Node *fa , *son[CHAR];
    int len , id , pos , g;
    SAM_Node(){}
    SAM_Node(int _len){
        g = 0;
        fa = 0;
        len = _len;
        RST(son);
    }
};
SAM_Node node[LEN << 1] , *root , *last;
int SAM_size;
SAM_Node * newNode(int len){
    node[SAM_size] = SAM_Node(len);
    node[SAM_size].id = SAM_size;
    return &node[SAM_size++];
}
SAM_Node *newNode(SAM_Node * p){
    node[SAM_size] = *p;
    node[SAM_size].id = SAM_size;
    return &node[SAM_size++];
}
void init(){
    SAM_size = 0;
    root = last = newNode(0);
    node[0].pos = 0;
}
void add(int x , int len){
    SAM_Node *p = last , *np = newNode(p -> len + 1);
    np -> pos = len;
    last = np;
    for( ; p && !p -> son[x] ; p = p -> fa)
        p -> son[x] = np;
    if (!p){
        np -> fa = root;
        return;
    }
    SAM_Node *q = p -> son[x];
    if (q -> len == p -> len + 1){
        np -> fa = q;
        return;
    }
    SAM_Node * nq = newNode(q);
    nq -> len = p -> len + 1;
    q -> fa = nq;
    np -> fa = nq;
    for ( ; p && p -> son[x] == q ; p = p -> fa)
        p -> son[x] = nq;
}
void build(char * s){
    init();
    int len = strlen(s);
    REP(i , len)
        add(s[i] - 'a' , i + 1);
}
}using namespace SAM;

char str[N];
int dp[N] , n , topocnt[N];
SAM_Node *topsam[LEN];
void solve(){
    n = strlen(str);
    build(str);
    RST(topocnt);
    REP(i , SAM_size)
        topocnt[node[i].len] ++;
    REP_1(i , n) topocnt[i] += topocnt[i - 1];
    REP(i , SAM_size) topsam[ -- topocnt[node[i].len] ] = &node[i];
    REP(i , n) (root = root -> son[str[i] - 'a']) -> g++;
    RST(dp);
    for (int i = SAM_size - 1 ; i > 0 ; i--){
        checkMax(dp[ topsam[i] -> len ] , topsam[i] -> g);
        if (topsam[i] -> fa) topsam[i] -> fa -> g += topsam[i] -> g;
    }
    for (int i = n - 1 ; i > 0 ; i--) checkMax(dp[i] , dp[i + 1]);
    REP_1(i , n) printf("%d\n" , dp[i]);
}
int main(){
    while(~scanf("%s" , str)) solve();
}


http://www.spoj.pl/problems/LCS/

const int N = 250009;
const int CHAR = 26;
namespace SAM{
    struct Node{
        Node * fa , *next[CHAR];
        int len , id , pos;
        Node(){}
        Node(int _len){
            fa = 0;
            len = _len;
            RST(next);
        }
    };
    Node node[N << 1] , *root , *last;
    int size;
    Node * newnode(int len){
        node[size] = Node(len);
        node[size].id = size;
        return &node[size++];
    }
    Node * newnode(Node * p){
        node[size] = *p;
        node[size].id = size;
        return &node[size++];
    }
    void init(){
        size = 0;
        root = last = newnode(0);
        node[0].pos = 0;
    }
    void add(int x , int len){
        Node *p = last , *np = newnode(p -> len + 1);
        np -> pos = len;
        last = np;
        for( ; p && !p -> next[x] ; p = p -> fa)
            p -> next[x] = np;
        if (!p){
            np -> fa = root;
            return;
        }
        Node *q = p -> next[x];
        if (q -> len == p -> len + 1){
            np -> fa = q;
            return;
        }
        Node * nq = newnode(q);
        nq -> len = p -> len + 1;
        q -> fa = nq;
        np -> fa = nq;
        for( ; p && p -> next[x] == q ; p = p -> fa)
            p -> next[x] = nq;
    }
    void build(char * s){
        init();
        int l = strlen(s);
        REP(i , l)
            add(s[i] - 'a' , i + 1);
    }
}using namespace SAM;
char str[N] , s[N];
int ans , l , n , topcnt[N];
Node* topo[N << 1] , *now;
void solve(){
    n = strlen(str);
    build(str);
    RST(topcnt);
    REP(i , size)
        topcnt[node[i].len]++;
    REP_1(i , n) topcnt[i] += topcnt[i - 1];
    REP(i , size) topo[ -- topcnt[node[i].len] ]  = &node[i];
    n = strlen(s);
    ans = 0 , l = 0;
    now = root;
    REP(i , n){
        int x = s[i] - 'a';
        if(now -> next[x]){
            l++;
            now = now -> next[x];
        }
        else{
            while(now && now -> next[x] == NULL)
                now = now -> fa;
            if (!now){
                l = 0;
                now = root;
            }
            else{
                l = now -> len + 1;
                now = now -> next[x];
            }
        }
        checkMax(ans , l);
    }
    OT(ans);
}
int main(){
    while(~scanf("%s%s" , str , s)) solve();
}


http://www.spoj.pl/problems/LCS2/ 

const int N = 100009;
const int CHAR = 26;
namespace SAM{
    struct Node{
        Node * fa , *next[CHAR];
        int len , id , pos;
        int curlen , minlen;
        Node(){}
        Node(int _len){
            fa = 0;
            len = _len;
            RST(next);
        }
    };
    Node node[N << 1] , *root , *last;
    int size;
    Node * newnode(int len){
        node[size] = Node(len);
        node[size].id = size;
        return &node[size++];
    }
    Node * newnode(Node * p){
        node[size] = *p;
        node[size].id = size;
        return &node[size++];
    }
    void init(){
        size = 0;
        root = last = newnode(0);
        node[0].pos = 0;
    }
    void add(int x , int len){
        Node *p = last , *np = newnode(p -> len + 1);
        np -> pos = len;
        last = np;
        for( ; p && !p -> next[x] ; p = p -> fa)
            p -> next[x] = np;
        if (!p){
            np -> fa = root;
            return;
        }
        Node *q = p -> next[x];
        if (q -> len == p -> len + 1){
            np -> fa = q;
            return;
        }
        Node * nq = newnode(q);
        nq -> len = p -> len + 1;
        q -> fa = nq;
        np -> fa = nq;
        for( ; p && p -> next[x] == q ; p = p -> fa)
            p -> next[x] = nq;
    }
    void build(char * s){
        init();
        int l = strlen(s);
        REP(i , l)
            add(s[i] - 'a' , i + 1);
    }
}using namespace SAM;
char str[N];
int ans , l , n , topcnt[N];
Node* topo[N << 1] , *now;
void solve(){
    n = strlen(str);
    build(str);
    RST(topcnt);
    REP(i , size)
        topcnt[node[i].len]++;
    REP_1(i , n) topcnt[i] += topcnt[i - 1];
    for (int i = size - 1 ; i >= 0 ; --i) topo[ -- topcnt[node[i].len] ]  = &node[i];
    REP(i , size){
        topo[i] -> minlen = topo[i] -> len;
    }
    while(~scanf("%s" , str)){
        REP(i , size) topo[i] -> curlen = 0;
            int len = 0; now = root;
        REP_C(i , strlen(str)){
//                OT(str[i]);
            int x = str[i] - 'a';
            while(now -> fa && now -> next[x] == NULL) now = now -> fa , len = now -> len;
            if(now -> next[x]){
                len++;
                now = now -> next[x];
                checkMax(now -> curlen , len);
            }
            else{
                len = 0;
                now = root;
            }
        }
        for (int i = size - 1 ; i >= 0 ; --i){
            now = topo[i];
            checkMin(now -> minlen , now -> curlen);
            if (now -> fa) checkMax(now -> fa -> curlen , now -> curlen);
        }
    }
    ans = 0;
    for (int i = 0 ; i < size ; ++i)
        checkMax(ans , node[i].minlen);
    OT(ans);
}
int main(){
    scanf("%s" , str); solve();
}


http://www.spoj.pl/problems/SUBLEX/ 
http://acm.hdu.edu.cn/showproblem.php?pid=4436 
http://acm.hdu.edu.cn/showproblem.php?pid=4416 
http://acm.hdu.edu.cn/showproblem.php?pid=4270 
http://codeforces.com/contest/235/problem/C



内容概要:《2024年中国城市低空经济发展指数报告》由36氪研究院发布,指出低空经济作为新质生产力的代表,已成为中国经济新的增长点。报告从发展环境、资金投入、创新能力、基础支撑和发展成效五个维度构建了综合指数评价体系,评估了全国重点城市的低空经济发展状况。北京和深圳在总指数中名列前茅,分别以91.26和84.53的得分领先,展现出强大的资金投入、创新能力和基础支撑。低空经济主要涉及无人机、eVTOL(电动垂直起降飞行器)和直升机等产品,广泛应用于农业、物流、交通、应急救援等领域。政策支持、市场需求和技术进步共同推动了低空经济的快速发展,预计到2026年市场规模将突破万亿元。 适用人群:对低空经济发展感兴趣的政策制定者、投资者、企业和研究人员。 使用场景及目标:①了解低空经济的定义、分类和发展驱动力;②掌握低空经济的主要应用场景和市场规模预测;③评估各城市在低空经济发展中的表现和潜力;④为政策制定、投资决策和企业发展提供参考依据。 其他说明:报告强调了政策监管、产业生态建设和区域融合错位的重要性,提出了加强法律法规建设、人才储备和基础设施建设等建议。低空经济正加速向网络化、智能化、规模化和集聚化方向发展,各地应找准自身比较优势,实现差异化发展。
### Ultralytics SAM Documentation and Resources Ultralytics provides comprehensive documentation and resources for using the Segment Anything Model (SAM), which is designed to perform object segmentation tasks efficiently. The official Ultralytics GitHub repository serves as an essential resource where users can find detailed guides on installation, usage examples, and advanced configurations. The primary entry point for accessing these materials includes: - **GitHub Repository**: This contains all necessary files including source code, pre-trained models, and tutorials. Users are encouraged to explore this repository for up-to-date information[^3]. - **Documentation Website**: A dedicated section within the Ultralytics website offers structured documentation covering setup instructions, model training, inference processes, and troubleshooting tips. This site also features API references that detail available functions and parameters used in SAM[^4]. For developers interested in integrating SAM into larger systems or custom applications, additional support comes from community forums and issue trackers hosted alongside the main project repositories. These platforms facilitate peer learning through discussions about best practices, common challenges faced during implementation phases, along with direct feedback channels between contributors and maintainers of the software package. To get started quickly, sample scripts demonstrating basic operations such as loading images, performing predictions, visualizing results, etc., have been provided both inside README.md documents found throughout subdirectories under `examples/` paths relative to root folder locations specified by each respective release version tag applied against commits made public via Git hosting services like GitHub.com. ```python from ultralytics import sam model = sam.SAM() # Initialize SAM instance. result = model(image_path='example.jpg') # Perform prediction on input image file path 'example.jpg'. print(result) # Output predicted segments data structure containing class labels associated probabilities scores per pixel location across entire canvas area covered by original photograph dimensions. ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值