uva_644暴力加字典树解法
来源:互联网 发布:数据库 什么是触发器 编辑:程序博客网 时间:2024/06/05 17:09
暴力
#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;}
0 0
- uva_644暴力加字典树解法
- uva_644
- HDUOJ 1004 Let the Balloon Rise ——三种解法:字典树,暴力,排序
- hdu1075字典树解法
- 字典树 (解析加模版)
- 字典树 (解析加模版)
- uva3942 字典树加dp
- POJ2945 Find the Clones(暴力 & 字典树)
- HDU5536-暴力|01字典树-J
- hdu1394 暴力解法~
- 暴力求解法入门
- 暴力求解法
- 【HDU5536 2015长春赛区 J】【字典树or暴力】Chip Factory 字典序做法+暴力做法
- 暴力求字典序
- UVA3942(字典树加DP)
- Xor Sum(字典树加贪心)
- 暴力求解法 最大乘积
- 约瑟夫环的暴力解法
- 聊聊并发——生产者消费者模式
- Hook api! 如何拦截系统api, 让它做你想做的事!
- LeetCode——LRU Cache
- Launcher与普通Activity的区别
- 九度1019
- uva_644暴力加字典树解法
- VMware error ubuntu13.04 upgrade 14.04
- android 开发时出现 Please ensure that adb is correctly located at '...\adb.exe' and can be executed
- Go Launcher桌面 1.41
- 使用调试钩子屏蔽全局钩子
- 动手学Android之五——布局初步(二)
- 我的vim7.3配置过程.
- Android修炼之道—时间测量
- mutex_lock() -- 互斥锁