10.7 模擬賽
阿新 • • 發佈:2018-11-08
這次考試就非常的真實 T3正解寫了一年甚至沒有寫70分 被踩
T1 decode
題目大意:
給一些huffman編碼的對映關係 求原串
思路:
暴力寫
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9View Code#include<map> 10 #define inf 2139062143 11 #define ll long long 12 #define MAXN 100100 13 using namespace std; 14 inline int read() 15 { 16 int x=0,f=1;char ch=getchar(); 17 while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();} 18 while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();} 19 returnx*f; 20 } 21 //yyc score=0 22 int tr[MAXN][2],n,end[MAXN],tot,len; 23 char ch[60][60],s[MAXN]; 24 void ins(int x) 25 { 26 len=strlen(s);int pos=0; 27 for(int i=0;i<len;i++) 28 { 29 if(!tr[pos][s[i]-'0']) tr[pos][s[i]-'0']=++tot; 30 pos=tr[pos][s[i]-'0']; 31 } 32 end[pos]=x;33 } 34 int main() 35 { 36 freopen("decode.in","r",stdin); 37 freopen("decode.out","w",stdout); 38 n=read(); 39 for(int i=1;i<=n;i++) {scanf("%s%s",s,ch[i]);ins(i);} 40 scanf("%s",s);len=strlen(s); 41 for(int i=0,pos=0;i<len;i++) 42 { 43 pos=tr[pos][s[i]-'0']; 44 if(end[pos]) {printf("%s",ch[end[pos]]);pos=0;} 45 } 46 }
T2 build
題目大意&思路:
dij裸題
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<map> 10 #define inf 2139062143 11 #define ll long long 12 #define MAXN 100100 13 using namespace std; 14 inline int read() 15 { 16 int x=0,f=1;char ch=getchar(); 17 while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();} 18 while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();} 19 return x*f; 20 } 21 //yyc score=0 22 int tr[MAXN][2],n,end[MAXN],tot,len; 23 char ch[60][60],s[MAXN]; 24 void ins(int x) 25 { 26 len=strlen(s);int pos=0; 27 for(int i=0;i<len;i++) 28 { 29 if(!tr[pos][s[i]-'0']) tr[pos][s[i]-'0']=++tot; 30 pos=tr[pos][s[i]-'0']; 31 } 32 end[pos]=x; 33 } 34 int main() 35 { 36 freopen("decode.in","r",stdin); 37 freopen("decode.out","w",stdout); 38 n=read(); 39 for(int i=1;i<=n;i++) {scanf("%s%s",s,ch[i]);ins(i);} 40 scanf("%s",s);len=strlen(s); 41 for(int i=0,pos=0;i<len;i++) 42 { 43 pos=tr[pos][s[i]-'0']; 44 if(end[pos]) {printf("%s",ch[end[pos]]);pos=0;} 45 } 46 }View Code
T3 circuit
題目大意:
一些個64位數 求編號在$[n-k-1,n+k+1]$中的所有串與它的異或和最大的數的編號(儘量靠前)
思路:
trie樹裸題 只不過卡空間
需要把一條鏈縮成一個點來省空間
(非常慘的寫掛了)(只能放石神的程式碼)
1 #include<algorithm> 2 #include<cmath> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cstring> 6 #include<ctime> 7 #include<iomanip> 8 #include<iostream> 9 #include<map> 10 #include<queue> 11 #include<stack> 12 #include<vector> 13 #define rep(i,x,y) for(register int i=(x);i<=(y);i++) 14 #define dwn(i,x,y) for(register int i=(x);i>=(y);i--) 15 #define LL long long 16 #define ull unsigned long long 17 #define maxn 500001 18 #define maxnd 1000001 19 using namespace std; 20 int read() 21 { 22 int x=0,f=1;char ch=getchar(); 23 while(!isdigit(ch)&&ch!='-')ch=getchar(); 24 if(ch=='-')f=-1,ch=getchar(); 25 while(isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar(); 26 return x*f; 27 } 28 ull ullread() 29 { 30 ull x=0;char ch=getchar(); 31 while(!isdigit(ch)&&ch!='-')ch=getchar(); 32 while(isdigit(ch))x=(x<<((ull)1))+(x<<((ull)3))+ch-'0',ch=getchar(); 33 return x; 34 } 35 void write(int x) 36 { 37 int f=0;char ch[20]; 38 if(!x){putchar('0'),putchar('\n');return;} 39 if(x<0)x=-x,putchar('-'); 40 while(x)ch[++f]=x%10+'0',x/=10; 41 while(f)putchar(ch[f--]); 42 putchar('\n'); 43 } 44 ull a[maxn],w[maxnd]; 45 int ch[maxnd][2],len[maxnd],hd[maxnd],tl[maxnd],siz[maxnd],cnt,n,k; 46 vector<int>v[maxnd]; 47 void ins(int u,int x) 48 { 49 while(hd[u]<=tl[u]&&v[u][tl[u]]>=x)tl[u]--; 50 tl[u]++; 51 if(tl[u]>=v[u].size())v[u].push_back(x); 52 else v[u][tl[u]]=x; 53 } 54 void del(int u,int x){while(hd[u]<=tl[u]&&v[u][hd[u]]<x)hd[u]++;} 55 void ext(ull x,int id) 56 { 57 int u=0,now=63;ull now1=((ull)1)<<63; 58 while(len[u]!=-1) 59 { 60 ull to=(x&now1)?1:0; 61 siz[u]++; 62 if(ch[u][to]==0) 63 { 64 ch[u][to]=++cnt,siz[cnt]=1,w[cnt]=x,len[cnt]=-1;ins(cnt,id); 65 break; 66 } 67 else 68 { 69 ull tpx;int tond=ch[u][to]; 70 tpx=(x>>(len[tond]+1)); 71 if(w[tond]==tpx) 72 { 73 if(len[tond]==-1){siz[tond]++,ins(tond,id);break;} 74 else {u=tond,now=len[u],now1=((ull)1)<<len[u],x%=now1<<1;} 75 } 76 else 77 { 78 int nd=++cnt,nw=to,p;ch[u][to]=++cnt; 79 dwn(i,now,1) 80 { 81 if(((w[tond]<<(len[tond]+1))>>i)==(x>>i))nw=(x>>i),p=i; 82 else break; 83 } 84 siz[cnt]=siz[tond]+1,siz[nd]=1; 85 w[cnt]=nw,len[cnt]=p-1,w[nd]=x%(((ull)1)<<p),len[nd]=-1,w[tond]=((w[tond]<<(len[tond]+1))%((ull)1<<p))>>(len[tond]+1); 86 int to2=(x&(((ull)1)<<(p-1)))?1:0; 87 ch[cnt][to2]=nd,ch[cnt][to2^1]=tond; 88 ins(nd,id); 89 break; 90 } 91 } 92 } 93 return; 94 } 95 void dlt(ull x,int id) 96 { 97 int u=0,now=63;ull now1=(((ull)1)<<63); 98 while(len[u]!=-1) 99 { 100 ull to=(x&now1)?1:0; 101 siz[u]--; 102 u=ch[u][to]; 103 now=len[u],now1=((ull)1<<now); 104 } 105 siz[u]--; 106 del(u,id); 107 return; 108 } 109 int getans(ull x) 110 { 111 int u=0,now=63;ull now1=(((ull)1)<<63); 112 while(len[u]!=-1) 113 { 114 ull to=(x&now1)?0:1; 115 if(ch[u][to]&&siz[ch[u][to]])u=ch[u][to]; 116 else u=ch[u][to^1]; 117 now=len[u],now1=((ull)1<<now); 118 } 119 return v[u][hd[u]]; 120 } 121 int main() 122 { 123 freopen("circuit.in","r",stdin); 124 freopen("circuit.out","w",stdout); 125 len[0]=63; 126 memset(tl,-1,sizeof(tl)); 127 n=read(),k=read(); 128 rep(i,1,n){a[i]=ullread();} 129 rep(i,1,k+1)ext(a[i],i); 130 rep(i,1,n) 131 { 132 if(i-k-2>=1)dlt(a[i-k-2],i-k-1); 133 if(i+k+1<=n)ext(a[i+k+1],i+k+1); 134 int ans=getans(a[i]); 135 write(ans-1); 136 } 137 return 0; 138 }View Code