POJ3630 Phone List 題解&程式碼
第一次用vim寫程式碼…感覺爽爽噠,終於明白很多程式碼為什麼會有詭異的空格什麼的…習慣
vim的快捷操作幾乎全部是和單詞相關,也就是說如果一句程式碼中間沒有空格…vim的優勢就完全消失了
在下的習慣一時半會改不過來…嘛,不過既然看到了其道理自然是要努力改的
裸的trie樹,最後加上一遍dfs,dfs檢驗是不是有一條路徑上同時有兩個單詞結尾,如果有輸出NO,反之則反
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxl=100005 ;
int T,n,tot,ch[maxl][20],flag[maxl],Flag;
char s[20];
int newnode(int x,int temp)
{
if(temp!=-1)ch[x][temp]=++tot;
for(int i=0;i<10;i++)ch[tot][i]=0;
flag[tot]=0;
}
void Insert(int len)
{
int x=0,p=0,temp;
while(p<len)
{
temp=s[p]-'0';
if(!ch[x][temp])newnode(x,temp);
x=ch[x][temp];
p++;
}
flag[x]=1 ;
}
void dfs(int x)
{
if(Flag)return;
if(flag[x]>1)Flag=true;
for(int i=0;i<10;i++)
if(ch[x][i])
flag[ch[x][i]]+=flag[x],dfs(ch[x][i]);
}
int main(void)
{
scanf("%d",&T);
while(T--)
{
Flag=false;
tot=0;
newnode(0,-1);
scanf ("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",s);
Insert(strlen(s));
}
dfs(0);
if(Flag)printf("NO\n");
else printf("YES\n");
}
return 0;
}
相關推薦
POJ3630 Phone List 題解&程式碼
第一次用vim寫程式碼…感覺爽爽噠,終於明白很多程式碼為什麼會有詭異的空格什麼的…習慣 vim的快捷操作幾乎全部是和單詞相關,也就是說如果一句程式碼中間沒有空格…vim的優勢就完全消失了 在下的習慣一時半會改不過來…嘛,不過既然看到了其道理自然是要努力改的
poj3630:Phone List——題解
can esp har targe name using problem style insert http://poj.org/problem?id=3630 簡單的trie樹問題,先添加,然後每個跑一邊看中途有沒有被打上結束標記即可。 #include<c
[POJ3630]Phone List (Tire)
class ostream inf ret n) code problem ack har 題意 trie字典樹模板 LOJ有中文翻譯https://loj.ac/problem/10049 思路 TIRE 代碼 之前在LOJ上做過 直接交了 #in
POJ3630 Phone List(字典樹)
題解: 字典樹判斷該字串是不是串集裡某個字串字首 程式碼 #include <cstdio> #include <queue> #include <cstring> #include <iostream&g
Phone List題解(字典樹)
// 12 7 // by qiu // funtion trie #include <cstdio> #include <cstdlib> #include <malloc.h> #include <cstring> typedef struct nod
【POJ 3630】Phone List 中文題意&題解&程式碼(C++)
Phone List Time Limit: 1000MS Memory Limit: 65536K Description Given a list of phone numbers, determine if it is consistent
【POJ3630】Phone List(字典樹)
problem 給定n個長度不超過10的數字串(n<10^4) 問其中是否存在兩個陣列串a,b,滿足a是b的字首。存在輸出NO,不存在輸出YES solution 將所有數字串構建成字典樹 在插入過程中,如果沒有新建任何節點(當前串是之前串
POJ3630/HDU-1671 Phone List,字典樹靜態建樹!
POJ動態建樹TLE了~~~ 題意:撥打某個電話時可能會因為和其他電話號碼的前幾位重複而導致錯誤,現在給出一張電話單,求是否有某個電話是其他電話的字首。是則輸出NO,否則輸出YES。 思路:字典樹模板題了,但有一個動態建樹每次都要清空記憶體這
POJ 3630 Phone List(字串字首重複)題解
DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number i
Timus : 1002. Phone Numbers 題解
targe sta hone cin 組合 name emp clas keys 把電話號碼轉換成為詞典中能夠記憶的的單詞的組合,找到最短的組合。 我這道題應用到的知識點: 1 Trie數據結構 2 map的應用 3 動態規劃法Word Break的
Phone List
min sca his algorithm test you ber scrip using Time Limit: 1000MS Memory Limit: 65536K Description Given a list of phone numbers,
Phone List HDU - 1671(Trie樹的基本運用)
題意: 給你多個由0-9構成的字串集合,問你這個集合中是否有一個字串是其他字串的字首? 分析: 直接構造字典樹,然後一一插入每個字串,判斷是否有比當前字串短或長的同一路徑的字
POJ 3630 - Phone List - [字典樹]
題目連結:http://poj.org/problem?id=3630 Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let
poj--3630 Phone List(Trie字典樹)
3630-Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34575 Accepted: 9924 Description Given a l
POJ 3630 Phone List
連結 http://poj.org/problem?id=3630 大意 給定一些串,判斷是否有一個串是另一個串的字首 思路 比較容易想到 h
1671 Phone List (字典樹模板)
Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone cat
【POJ2406】Power Strings 中文題意&題解&程式碼(C++)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Description Given two strings a and b we define a*b to be their conca
HDU 1671.Phone List【字典樹】【5月15】
Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed th
HDU 1698 Just a Hook 題解&程式碼
題目要求是對於一個初始值均為1的區間進行區間修改,修改目標為:[a,b]區間內的值被修改為c 對於多組資料的每組資料輸出q次修改後的全區間和 基本線段樹了…只有兩個元素需要維護:sum和add,su
Phone List [trie樹]
傳送門 我們邊插入邊判斷 , 首先要判斷插入的串有沒有包含其它的串 , 我們邊插入邊看節點有沒有值就可以了 其次要判斷這個串有沒有被包含 , 我們插入的時候看有沒有新增節點就好 #include<bits/stdc++.h> #define N 10050 u