由于 $T3$ 是清华的题目,本次题目和 $T3$ 不公开。
T1
暴力或 $Trie$ 树瞎**搞。
但是我太菜了,打成了普通的连字母边的 $Trie$ 树,把插入的 $01$ 串的每位都减了 $'a'$…… 然而很叼的是是我的 $Trie$ 数组的儿子指针开的是 $26$ 位(按照字母开的),然后 $0/1$ 下标正好炸回了这个范围内,魔过了-_-
主要是今天做不动,随手打完一次过样例就不看了……
1 #include<bits/stdc++.h> 2 using namespace std; 3 inline int read(){ 4 int x=0; bool f=1; char c=getchar(); 5 for(;!isdigit(c);c=getchar()) if(c=='-') f=0; 6 for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0'); 7 if(f) return x; 8 return 0-x; 9 } 10 int n; 11 char c[10005],put[1]; 12 namespace Trie{ 13 int tr[500001][2],cnt; 14 char tag[500001]; 15 void insert(int id){ 16 int len=strlen(c),v,u=0; 17 for(int i=0;i^len;++i){ 18 v=c[i]-'0'; 19 if(!tr[u][v]) tr[u][v]=++cnt; 20 u=tr[u][v]; 21 } 22 tag[u]=put[0]; 23 } 24 }; 25 using namespace Trie; 26 27 int main(){ 28 freopen("decode.in","r",stdin); 29 freopen("decode.out","w",stdout); 30 n=read(); 31 int i; 32 for(i=1;i<=n;++i){ 33 scanf("%s%s",c,put); 34 insert(i); 35 } 36 scanf("%s",c); 37 int len=strlen(c),u=0; 38 for(i=0;i^len;++i){ 39 u=tr[u][c[i]-'0']; 40 if(tag[u]) putchar(tag[u]), u=0; 41 } 42 return 0; 43 }
T2
$Dijkstra$ 板子题。
1 #include<bits/stdc++.h> 2 #define mp make_pair 3 #define N 100002 4 #define M 200002 5 using namespace std; 6 inline int read(){ 7 int x=0; bool f=1; char c=getchar(); 8 for(;!isdigit(c);c=getchar()) if(c=='-') f=0; 9 for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0'); 10 if(f) return x; 11 return 0-x; 12 } 13 int n,m,t[N],ans[N]; 14 bool vis[N]; 15 priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > >Q; 16 struct edge{ 17 int v,nxt; 18 }e[M<<1]; 19 int head[N],cnt; 20 inline void add(int u,int v){e[++cnt]=(edge){v,head[u]}, head[u]=cnt;} 21 22 int main(){ 23 freopen("build.in","r",stdin); 24 freopen("build.out","w",stdout); 25 n=read(),m=read(); 26 int i,u,v; 27 for(i=1;i<=n;++i) t[i]=read(); 28 for(i=0;i^m;++i) u=read(),v=read(),add(u,v),add(v,u); 29 memset(ans,0x7f,sizeof ans); 30 Q.push(mp(t[1],1)), vis[1]=1, ans[1]=t[1]; 31 while(!Q.empty()){ 32 u=Q.top().second, Q.pop(), vis[u]=1; 33 //printf("come:%d ",u); 34 for(int i=head[u];i;i=e[i].nxt) 35 if(!vis[e[i].v] && ans[e[i].v]>ans[u]+t[e[i].v]){ 36 ans[e[i].v]=ans[u]+t[e[i].v], Q.push(mp(ans[e[i].v],e[i].v)); 37 //printf("%d->%d %d %d %d ",u,e[i].v,ans[u],t[e[i].v],ans[e[i].v]); 38 } 39 } 40 for(i=1;i<=n;++i) printf("%d ",ans[i]); 41 return 0; 42 }