zoukankan      html  css  js  c++  java
  • poj 1056 IMMEDIATE DECODABILITY

    trie树模板题。题目主要是看前缀,因此只要碰到染色节点就false就行了。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #define root 1
    using namespace std;
    int cnt=0,cntnode=1;
    int child[1005][15],flag[1005];
    char s[1005];
    bool insert(int x,int num,int limit)
    {
    int r;
    if (s[num]=='0') r=0;
    else r=1;
    if (flag[x]==1) return false;
    else
    {
    if (child[x][r]==0)
    {
    child[x][r]=++cntnode;
    if (num!=limit) return insert(child[x][r],num+1,limit);
    }
    else
    if (num!=limit) return insert(child[x][r],num+1,limit);
    if (num==limit)
    {
    if (flag[child[x][r]]==1) return false;
    flag[child[x][r]]=1;
    return true;
    }
    }
    }
    int main()
    {
    while (scanf("%s",s)!=EOF)
    {
    int judge=0;
    cnt++;
    memset(child,0,sizeof(child));
    memset(flag,0,sizeof(flag));
    cntnode=1;
    int l=strlen(s);
    if (insert(root,0,l-1)==false) judge=1;
    for (;;)
    {
    scanf("%s",s);
    int l=strlen(s);
    if (s[0]=='9') break;
    if (insert(root,0,l-1)==false) judge=1;
    }
    if (judge==0) printf("Set %d is immediately decodable ",cnt);
    else printf("Set %d is not immediately decodable ",cnt);
    }
    return 0;
    }

  • 相关阅读:
    掌握MySQL 2
    掌握MySQL 1
    掌握并发编程3
    网络编程—SOCKET开发
    掌握并发编程2
    掌握并发编程1
    网络编程知识点
    osi五层协议
    C#中使用正则表达式验证电话号码、手机号、身份证号、数字和邮编
    C#中Convert和parse的区别
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/5111696.html
Copyright © 2011-2022 走看看