暴力

#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. 非Qt工程使用Qt的信号槽机制

    非Qt工程,使用Qt的信号槽机制,蛋疼不?反正我现在就是要做这样一件蛋疼的事. 要使用Qt的信号槽机制,下面是从Qt Assist里面关于 signal & slots 的一句介绍: All ...

  2. iOS开发中权限再度梳理

    前言 上篇文章iOS开发中的这些权限,你搞懂了吗?介绍了一些常用权限的获取和请求方法,知道这些方法的使用基本上可以搞定大部分应用的权限访问的需求.但是,这些方法并不全面,不能涵盖住所有权限访问的方法. ...

  3. UESTC--1269--ZhangYu Speech(模拟)

    ZhangYu Speech Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Submit ...

  4. Navicat 连接 Mysql 报2059错误的原因以及解决方法

    MySQL的8.0.*版本使用的是caching_sha2_password验证方式,而Navicat Premium 12还不支持该种方式.解决方案: 1,降低mysql的版本 2,设置mysql支 ...

  5. 18. 4Sum[M]四数之和

    题目 Given an array nums of n integers and an integer target, are there elements a, b, c and d in nums ...

  6. IIS之虚拟目录学习

    从刚实习开始就了解到虚拟目录这个词,但是一直没去研究过什么意思,而且也没实际用过.一晃两年过去了,今天正好趁休息,补补脑学习下. 通过百度了解到,虚拟目录创建的目的是为了应对磁盘容量爆满,部署的网站不 ...

  7. Sqlite简单操作

    1.student类 public class Student { int id; String name; String sex; String address; int money; public ...

  8. Aspx小记

    关闭按钮 protected void Close_Click(object sender, EventArgs e) { //Page.RegisterStartupScript("clo ...

  9. MySQL构造测试数据

    构造测试数据(笛卡尔积,6 次100 万) create table t1(id int, val varchar(80)); set @i := 0;create table tmp as sele ...

  10. Android 7.0 Gallery图库源码分析4 - SlotView手势监听及页面跳转

    上篇文章讲了初始化View时会实例化一个SlotView并监听其事件,至于它是怎么实现的,用的是Android自带的GestureDetector. GestureDetector是Android自带 ...