暴力

#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
int main()
{
int t=0,i=0;
char s[10][12];
bool a[12][12];
memset(s,'\0',sizeof(s));
while(scanf("%s",s[i])!=EOF)
{
if(s[i][0]=='9')
{
t++;
int state=1;
memset(a,false,sizeof(a));
for(int j=0;j<i;j++)
for(int k=j+1;k<=i;k++)
for(int l=0;s[j][l]!='\0'&&s[k][l]!='\0';l++)
{if(s[j][l]!=s[k][l])
{a[j][k]=true; //cout<<j<<k<<l<<endl;
}
//cout<<j<<k<<l<<endl;
//cout<<l<<s[k][l]<<endl;
}
for(int j=0;j<i;j++)
for(int k=j+1;k<=i;k++)
if(a[j][k]==false)
state=0;
if(!state)
printf("Set %d is not immediately decodable\n",t);
if(state==1)
printf("Set %d is immediately decodable\n",t);
memset(s,'\0',sizeof(s));
i=0;
}
else
i++;
}
return 0;
}

字典树

#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
int tree[5000][2];
int w[5000];
int numv=0;
char s[10][12];
void insert(char s[])
{ int u=0;
w[0]++;
int len=strlen(s);
for(int i=0; i<len; i++)
{
if(tree[u][s[i]-'0']==0)
{
tree[u][s[i]-'0']=++numv;
}
u=tree[u][s[i]-'0'];
w[u]++;
}
//cout<<w[1]<<w[2]<<endl;
}
bool find(char s[])
{
int u=0;
int len=strlen(s);
for(int i=0; i<len; i++)
{
u=tree[u][s[i]-'0'];
//cout<<w[u]<<" "<<u<<s[i]<<endl;
if(w[u]==1)
{
return true;
break;
}
}
return false;
}
int main()
{
int t=0,i=0;
bool a[12];
memset(s,'\0',sizeof(s));
while(scanf("%s",s[i])!=EOF)
{
if(s[i][0]=='9')
{
numv=0;
memset(tree,0,sizeof(tree));
memset(w,0,sizeof(w));
memset(a,false,sizeof(a));
t++;
int state=1;
for(int j=0; j<i; j++)
insert(s[j]);
for(int j=0; j<i; j++)
if(find(s[j])==true)
{
a[j]=true;
} for(int j=0; j<i; j++)
if(a[j]==false)
{state=0; //cout<<j<<"as"<<endl;
}
if(!state)
cout<<"Set "<<t<<" is not immediately decodable"<<endl;
else
cout<<"Set "<<t<<" is immediately decodable"<<endl;
memset(s,'\0',sizeof(s));
i=0;
}
else
i++;
}
return 0;
}

uva_644暴力加字典树解法的更多相关文章

  1. Chip Factory(HDU5536 + 暴力 || 01字典树)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目: 题意: 对于给定的n个数,求出三个下标不同的数使得(si+sj)^sk最大. 思路: ...

  2. Codeforces 979 字符串强制N变换最多出现字母 DFS子树 暴力01字典树

    A /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) ...

  3. hdu 2896 字典树解法

    #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...

  4. HDU 5536 Chip Factory (暴力+01字典树)

    <题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...

  5. Educational Codeforces Round 12 E. Beautiful Subarrays 字典树

    E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...

  6. hust 1605 - Gene recombination(bfs+字典树)

    1605 - Gene recombination Time Limit: 2s Memory Limit: 64MB Submissions: 264 Solved: 46 DESCRIPTION ...

  7. Phone List POJ-3630 字典树 or 暴力

    Phone List POJ-3630 字典树 or 暴力 题意 目前有 t 组数据, n 个电话号码,如果拨打号码的时候 先拨通了某个号码,那么这一串号码就无法全部拨通. 举个例子 911 和 91 ...

  8. hdu5536 Chip Factory 字典树+暴力 处理异或最大 令X=(a[i]+a[j])^a[k], i,j,k都不同。求最大的X。

    /** 题目:hdu5536 Chip Factory 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:给定n个数,令X=(a[i]+a[j] ...

  9. 从Trie树(字典树)谈到后缀树

    转:http://blog.csdn.net/v_july_v/article/details/6897097 引言 常关注本blog的读者朋友想必看过此篇文章:从B树.B+树.B*树谈到R 树,这次 ...

随机推荐

  1. ios Button

    展现效果例如以下: 功能说明: 1加入来图片背景, 2动态展现百度网页, 3动态加入button. 4展现提示框.展现你点击提示框得index  我成功来你也快来试试. 1 详细得项目创建与拖动but ...

  2. php常用知识集锦

    php常用知识集锦 很多位置都有写好的代码,自己做项目的时候可以直接拿来用,而不用自己写,比如现在看到的菜鸟教程. 1.判断是否为空 empty($_POST["name"]) 2 ...

  3. MEF example code

    public interface IObjectResolver { } public class ObjectResolver:IObjectResolver { private Compositi ...

  4. zeromq-4.1.2在windows下的编译

    作者:朱金灿 来源:http://blog.csdn.net/clever101 zeromq是一个最近比较火的跨平台消息中间件,最近准备研究它,故下载它的源码编译了一下.我是使用VS2008编译的, ...

  5. GradientDrawable类的利用动态设置样式中的颜色

    1.xml样式文件 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android=& ...

  6. 产品开发也要看阵容,APP开发只需五步变得靠谱

    最早认识的一个朋友是程序员,曾经到一家外包公司接单子,小外包公司经常遇到的问题就是和需求方谈产品功能.客户要做外包,对方让他一次性报价,但是客户连功能点自己都不清楚,这时朋友说还是按照具体功能点来做吧 ...

  7. 粘包_Server

    from socket import *# import subprocessip_port = ('127.0.0.1',8080)back_log = 5buffer_size = 1024tcp ...

  8. JS iframe给父类传值

    父类页面 <html><head> <script type="text/javascript">            function Ge ...

  9. 用 Java 技术创建 RESTful Web (服务 JAX-RS:一种更为简单、可移植性更好的替代方式)

    作者: Dustin Amrhein, 软件工程师, IBM Nick Gallardo, 软件工程师, IBM 出处: http://www.ibm.com/developerworks/cn/we ...

  10. php数组 匹配键值

    1.array_search() //判断键值是否在数组中,//存在,返回值对应的键;//不存在,返回false;//例子:$type = array( "选考" => 'o ...