http://acm.hdu.edu.cn/showproblem.php?pid=4686php
隊友推的矩陣快速冪,不知道HDU是用%I64d,在%lld被WA了幾回。。。ios
cin, cout會T。。。算法
矩陣:[sum, aibi, ai, bi, 1] 5*5的數組
注意特判n=0時輸出0網絡
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<string> 5 #include<algorithm> 6 #include<functional> 7 using namespace std; 8 typedef long long ll; 9 const int n=5; 10 struct mtx 11 { 12 ll x[10][10]; 13 void output() 14 { 15 for(int i=1; i<=n; i++) 16 { 17 for(int j=1; j<=n; j++) 18 cout<<x[i][j]<<" "; 19 cout<<endl; 20 } 21 22 } 23 }; 24 25 const ll mod = 1000000007; 26 mtx mtx_mul(mtx &aa,mtx &bb) 27 { 28 mtx s; 29 int i,j,k; 30 for(i=1; i<=n; i++) 31 for(j=1; j<=n; j++) 32 { 33 s.x[i][j] = 0; 34 for(k=1; k<=n; k++) 35 s.x[i][j] =(s.x[i][j]+aa.x[i][k]*bb.x[k][j])%mod; 36 } 37 return s; 38 } 39 mtx mtx_pow(mtx t,ll p) 40 { 41 mtx res; 42 int i,j; 43 for(i=0; i<=n; i++) 44 { 45 for(int j=1; j<=n; j++) res.x[i][j] = 0ll; 46 res.x[i][i] = 1ll; 47 } 48 while(p!=0) 49 { 50 if(p&1) res = mtx_mul(t,res); 51 p >>= 1; 52 t = mtx_mul(t,t); 53 } 54 return res; 55 } 56 57 int main() 58 { 59 //std::ios_base::sync_with_stdio(false); 60 ll p; 61 while(~scanf("%I64d",&p)) 62 { 63 ll ax,ay,bx,by,a0,b0; 64 scanf("%I64d%I64d%I64d",&a0,&ax,&ay); 65 //cin>>b0>>bx>>by; 66 scanf("%I64d%I64d%I64d",&b0,&bx,&by); 67 68 if(p == 0) 69 { 70 printf("0\n"); 71 continue; 72 } 73 74 mtx m; 75 for(int i=1; i<=n; i++) 76 for(int j=1; j<=n; j++) 77 m.x[i][j] = 0ll; 78 m.x[1][1] = 1ll; 79 m.x[2][1] = ax*bx; m.x[2][2] = ax*bx; 80 m.x[3][1] = ax*by; m.x[3][2] = ax*by; m.x[3][3] = ax; 81 m.x[4][1] = bx*ay; m.x[4][2] = bx*ay; m.x[4][4] = bx; 82 m.x[5][1] = ay*by; m.x[5][2] = ay*by; m.x[5][3] = ay; m.x[5][4] = by; m.x[5][5] = 1ll; 83 for(int i=1; i<=n; i++) 84 for(int j=1; j<=n; j++) 85 m.x[i][j] %= mod; 86 m = mtx_pow(m,p-1); 87 //m.output(); 88 ll kk[6]; 89 kk[1] = a0*b0; kk[2] = a0*b0; kk[3] = a0; kk[4] = b0; kk[5] = 1ll; 90 for(int i=1; i<=n; i++) 91 kk[i] %= mod; 92 ll ans = 0; 93 for(int i=1; i<=n; i++) 94 { 95 ans += kk[i]*m.x[i][1]; 96 ans %= mod; 97 } 98 printf("%I64d\n",ans); 99 } 100 return 0; 101 }
http://acm.hdu.edu.cn/showproblem.php?pid=4690ide
水題。。。學校機房網絡太渣,下載不了附件,而後手敲累死人。。。╮(╯_╰)╭spa
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<string> 5 #include<map> 6 #include<algorithm> 7 #include<functional> 8 using namespace std; 9 map<string,string> mp1; 10 map<string,string> mp2; 11 void init() 12 { 13 mp1.clear(); 14 mp2.clear(); 15 16 mp1["00"]="NUL"; 17 mp1["01"]="S0H"; 18 mp1["02"]="STX"; 19 mp1["03"]="ETX"; 20 mp1["05"]="HT"; 21 mp1["07"]="DEL"; 22 mp1["0B"]="VT"; 23 mp1["0C"]="FF"; 24 mp1["0D"]="CR"; 25 mp1["0E"]="S0"; 26 mp1["0F"]="SI"; 27 mp1["10"]="DLE"; 28 mp1["11"]="DC1"; 29 mp1["12"]="DC2"; 30 mp1["13"]="DC3"; 31 mp1["16"]="BS"; 32 mp1["18"]="CAN"; 33 mp1["19"]="EM"; 34 mp1["1C"]="IFS"; 35 mp1["1D"]="IGS"; 36 mp1["1E"]="IRS"; 37 mp1["1F"]="IUS ITB"; 38 mp1["25"]="LF"; 39 mp1["26"]="ETB"; 40 mp1["27"]="ESC"; 41 mp1["2D"]="ENQ"; 42 mp1["2E"]="ACK"; 43 mp1["2F"]="BEL"; 44 mp1["32"]="SYN"; 45 mp1["37"]="E0T"; 46 mp1["3C"]="DC4"; 47 mp1["3D"]="NAK"; 48 mp1["3F"]="SUB"; 49 mp1["40"]="SP"; 50 mp1["4B"]="."; 51 mp1["4C"]="<"; 52 mp1["4D"]="("; 53 mp1["4E"]="+"; 54 mp1["4F"]="|"; 55 mp1["50"]="&"; 56 mp1["5A"]="!"; 57 mp1["5B"]="$"; 58 mp1["5C"]="*"; 59 mp1["5D"]=")"; 60 mp1["5E"]=";"; 61 mp1["60"]="-"; 62 mp1["61"]="/"; 63 mp1["6B"]=","; 64 mp1["6C"]="%"; 65 mp1["6D"]="_"; 66 mp1["6E"]=">"; 67 mp1["6F"]="?"; 68 mp1["79"]="`"; 69 mp1["7A"]=":"; 70 mp1["7B"]="#"; 71 mp1["7C"]="@"; 72 mp1["7D"]="'"; 73 mp1["7E"]="="; 74 mp1["7F"]="\""; 75 mp1["81"]="a"; 76 mp1["82"]="b"; 77 mp1["83"]="c"; 78 mp1["84"]="d"; 79 mp1["85"]="e"; 80 mp1["86"]="f"; 81 mp1["87"]="g"; 82 mp1["88"]="h"; 83 mp1["89"]="i"; 84 mp1["91"]="j"; 85 mp1["92"]="k"; 86 mp1["93"]="l"; 87 mp1["94"]="m"; 88 mp1["95"]="n"; 89 mp1["96"]="o"; 90 mp1["97"]="p"; 91 mp1["98"]="q"; 92 mp1["99"]="r"; 93 mp1["A1"]="~"; 94 mp1["A2"]="s"; 95 mp1["A3"]="t"; 96 mp1["A4"]="u"; 97 mp1["A5"]="v"; 98 mp1["A6"]="w"; 99 mp1["A7"]="x"; 100 mp1["A8"]="y"; 101 mp1["A9"]="z"; 102 mp1["B0"]="^"; 103 mp1["BA"]="["; 104 mp1["BB"]="]"; 105 mp1["C0"]="{"; 106 mp1["C1"]="A"; 107 mp1["C2"]="B"; 108 mp1["C3"]="C"; 109 mp1["C4"]="D"; 110 mp1["C5"]="E"; 111 mp1["C6"]="F"; 112 mp1["C7"]="G"; 113 mp1["C8"]="H"; 114 mp1["C9"]="I"; 115 mp1["D0"]="}"; 116 mp1["D1"]="J"; 117 mp1["D2"]="K"; 118 mp1["D3"]="L"; 119 mp1["D4"]="M"; 120 mp1["D5"]="N"; 121 mp1["D6"]="O"; 122 mp1["D7"]="P"; 123 mp1["D8"]="Q"; 124 mp1["D9"]="R"; 125 mp1["E0"]="\\"; 126 mp1["E2"]="S"; 127 mp1["E3"]="T"; 128 mp1["E4"]="U"; 129 mp1["E5"]="V"; 130 mp1["E6"]="W"; 131 mp1["E7"]="X"; 132 mp1["E8"]="Y"; 133 mp1["E9"]="Z"; 134 mp1["F0"]="0"; 135 mp1["F1"]="1"; 136 mp1["F2"]="2"; 137 mp1["F3"]="3"; 138 mp1["F4"]="4"; 139 mp1["F5"]="5"; 140 mp1["F6"]="6"; 141 mp1["F7"]="7"; 142 mp1["F8"]="8"; 143 mp1["F9"]="9"; 144 145 mp2["NUL"]="00"; 146 mp2["S0H"]="01"; 147 mp2["STX"]="02"; 148 mp2["ETX"]="03"; 149 mp2["E0T"]="04"; 150 mp2["ENQ"]="05"; 151 mp2["ACK"]="06"; 152 mp2["BEL"]="07"; 153 mp2["BS"]="08"; 154 mp2["HT"]="09"; 155 mp2["LF"]="0A"; 156 mp2["VT"]="0B"; 157 mp2["FF"]="0C"; 158 mp2["CR"]="0D"; 159 mp2["S0"]="0E"; 160 mp2["SI"]="0F"; 161 mp2["DLE"]="10"; 162 mp2["DC1"]="11"; 163 mp2["DC2"]="12"; 164 mp2["DC3"]="13"; 165 mp2["DC4"]="14"; 166 mp2["NAK"]="15"; 167 mp2["SYN"]="16"; 168 mp2["ETB"]="17"; 169 mp2["CAN"]="18"; 170 mp2["EM"]="19"; 171 mp2["SUB"]="1A"; 172 mp2["ESC"]="1B"; 173 mp2["IFS"]="1C"; 174 mp2["IGS"]="1D"; 175 mp2["IRS"]="1E"; 176 mp2["IUS ITB"]="1F"; 177 mp2["SP"]="20"; 178 mp2["!"]="21"; 179 mp2["\""]="22"; 180 mp2["#"]="23"; 181 mp2["$"]="24"; 182 mp2["%"]="25"; 183 mp2["&"]="26"; 184 mp2["'"]="27"; 185 mp2["("]="28"; 186 mp2[")"]="29"; 187 mp2["*"]="2A"; 188 mp2["+"]="2B"; 189 mp2[","]="2C"; 190 mp2["-"]="2D"; 191 mp2["."]="2E"; 192 mp2["/"]="2F"; 193 mp2["0"]="30"; 194 mp2["1"]="31"; 195 mp2["2"]="32"; 196 mp2["3"]="33"; 197 mp2["4"]="34"; 198 mp2["5"]="35"; 199 mp2["6"]="36"; 200 mp2["7"]="37"; 201 mp2["8"]="38"; 202 mp2["9"]="39"; 203 mp2[":"]="3A"; 204 mp2[";"]="3B"; 205 mp2["<"]="3C"; 206 mp2["="]="3D"; 207 mp2[">"]="3E"; 208 mp2["?"]="3F"; 209 mp2["@"]="40"; 210 mp2["A"]="41"; 211 mp2["B"]="42"; 212 mp2["C"]="43"; 213 mp2["D"]="44"; 214 mp2["E"]="45"; 215 mp2["F"]="46"; 216 mp2["G"]="47"; 217 mp2["H"]="48"; 218 mp2["I"]="49"; 219 mp2["J"]="4A"; 220 mp2["K"]="4B"; 221 mp2["L"]="4C"; 222 mp2["M"]="4D"; 223 mp2["N"]="4E"; 224 mp2["O"]="4F"; 225 mp2["P"]="50"; 226 mp2["Q"]="51"; 227 mp2["R"]="52"; 228 mp2["S"]="53"; 229 mp2["T"]="54"; 230 mp2["U"]="55"; 231 mp2["V"]="56"; 232 mp2["W"]="57"; 233 mp2["X"]="58"; 234 mp2["Y"]="59"; 235 mp2["Z"]="5A"; 236 mp2["["]="5B"; 237 mp2["\\"]="5C"; 238 mp2["]"]="5D"; 239 mp2["^"]="5E"; 240 mp2["_"]="5F"; 241 mp2["`"]="60"; 242 mp2["a"]="61"; 243 mp2["b"]="62"; 244 mp2["c"]="63"; 245 mp2["d"]="64"; 246 mp2["e"]="65"; 247 mp2["f"]="66"; 248 mp2["g"]="67"; 249 mp2["h"]="68"; 250 mp2["i"]="69"; 251 mp2["j"]="6A"; 252 mp2["k"]="6B"; 253 mp2["l"]="6C"; 254 mp2["m"]="6D"; 255 mp2["n"]="6E"; 256 mp2["o"]="6F"; 257 mp2["p"]="70"; 258 mp2["q"]="71"; 259 mp2["r"]="72"; 260 mp2["s"]="73"; 261 mp2["t"]="74"; 262 mp2["u"]="75"; 263 mp2["v"]="76"; 264 mp2["w"]="77"; 265 mp2["x"]="78"; 266 mp2["y"]="79"; 267 mp2["z"]="7A"; 268 mp2["{"]="7B"; 269 mp2["|"]="7C"; 270 mp2["}"]="7D"; 271 mp2["~"]="7E"; 272 mp2["DEL"]="7F"; 273 } 274 int main() 275 { 276 init(); 277 char ch1,ch2; 278 string tmp; 279 while(~scanf("%c",&ch1)) 280 { 281 if(ch1=='\n') break; 282 scanf("%c",&ch2); 283 tmp.clear(); 284 tmp.push_back(ch1); 285 tmp.push_back(ch2); 286 tmp=mp2[mp1[tmp]]; 287 ch1=tmp[0]; 288 ch2=tmp[1]; 289 printf("%c%c",ch1,ch2); 290 } 291 puts(""); 292 return 0; 293 }
http://acm.hdu.edu.cn/showproblem.php?pid=46913d
隊友負責的後綴數組,我不懂這個。。。因而只能貼下代碼了。。。code
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <string> 5 #include <cmath> 6 #include <iostream> 7 using namespace std; 8 typedef long long ll; 9 const int M = 1e5+10; 10 int wa[M],wb[M],wv[M],wsum[M]; 11 int sa[M]; 12 int cmp(int *r,int a,int b,int l) 13 { 14 return r[a]==r[b] && r[a+l]==r[b+l]; 15 } 16 void da(int *r,int *sa,int n,int m) 17 { 18 int i,j,p,*x=wa,*y=wb,*t; 19 for(i=0; i<m; i++) 20 wsum[i]=0; 21 for(i=0; i<n; i++)wsum[x[i]=r[i]]++; 22 for(i=1; i<m; i++)wsum[i]+=wsum[i-1]; 23 for(i=n-1; i>=0; i--)sa[--wsum[x[i]]]=i; 24 for(j=1,p=1; p<n; j*=2,m=p) 25 { 26 for(p=0,i=n-j; i<n; i++)y[p++]=i; 27 for(i=0; i<n; i++)if(sa[i]>=j)y[p++]=sa[i]-j; 28 for(i=0; i<n; i++)wv[i]=x[y[i]]; 29 for(i=0; i<m; i++)wsum[i]=0; 30 for(i=0; i<n; i++)wsum[wv[i]]++; 31 for(i=1; i<m; i++)wsum[i]+=wsum[i-1]; 32 for(i=n-1; i>=0; i--)sa[--wsum[wv[i]]]=y[i]; 33 for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1; i<n; i++)x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++; 34 } 35 } 36 int height[M],rank[M]; 37 void calheight(int *r,int *sa,int n) 38 { 39 int i,j,k=0; 40 for(i=0; i<=n; i++)rank[sa[i]]=i; 41 for(i=0; i<n; height[rank[i++]]=k)for(k?k--:0,j=sa[rank[i]-1]; r[i+k]==r[j+k]; k++); 42 // for(int i=1; i<=n; i++) 43 // printf("%d ",height[i]); 44 // printf("\n"); 45 } 46 int f[M][30]; 47 void makeRMQ(int n) 48 { 49 int i,j,k,m; 50 m=(int)(log(1.0*n)/log(2.0)); 51 for(i=1; i<=n; i++)f[i][0]=height[i]; 52 for(i=1; i<=m; i++)for(j=n; j>=1; j--) 53 { 54 f[j][i]=f[j][i-1]; 55 k=1<<(i-1); 56 if(j+k<=n)f[j][i]=min(f[j][i],f[j+k][i-1]); 57 } 58 } 59 int LCP(int x,int y) 60 { 61 int m,t; 62 x=rank[x]; 63 y=rank[y]; 64 if(x>y) t=x,x=y,y=t; 65 x++; 66 m=(int)(log(1.0*(y-x+1))/log(2.0)); 67 return min(f[x][m],f[y-(1<<m)+1][m]); 68 } 69 int dig[M]; 70 void caldig() 71 { 72 memset(dig,0,sizeof(dig)); 73 dig[0] = 1; 74 for(int i=1;i<M;i++) 75 { 76 int tmp = i; 77 while(tmp) 78 { 79 dig[i] ++; 80 tmp/=10; 81 } 82 } 83 // cout<<dig[10]<<endl; 84 return ; 85 } 86 char s[M]; 87 int a[M]; 88 ll x,y; 89 int main(void) 90 { 91 caldig(); 92 while(~scanf("%s",s)) 93 { 94 int len = strlen(s); 95 for(int i=0; i<len; i++) 96 a[i] = s[i] - 'a' +1; 97 a[len] = 0; 98 da(a,sa,len+1,128); 99 calheight(a,sa,len); 100 makeRMQ(len); 101 int qu; 102 scanf("%d",&qu); 103 x=0,y=0; 104 int l,r,dis; 105 scanf("%d%d",&l,&r); 106 x += (r-l+1),y += (r-l+3); 107 int lastl = l,lastr = r; 108 for(int i = 2; i<= qu; i++) 109 { 110 scanf("%d%d",&l,&r); 111 x += (r-l+1); 112 y += 2; 113 if(lastl == l) dis = min(lastr,r) - l; 114 else 115 { 116 int lx = LCP(lastl,l); 117 // cout<<"lx: "<<lx<<endl; 118 dis = min(min(lx,r-l),lastr - lastl); 119 } 120 y += dig[dis]; 121 y += (r-l-dis); 122 lastl = l ,lastr = r; 123 } 124 printf("%I64d %I64d\n",x,y); 125 } 126 }
一、此次比賽罰時高了,主要都是用cin引發的,1001和1005都是由於cin T了幾回。。blog
二、發現咱們隊的後勁不足,前2個半小時A了3題,而後後面一道都沒出來。。。連續幾回訓練都是如此。。
三、算法的覆蓋面不夠。。1002貼板題,可是帶花樹算法沒據說過。。因而出不來。。
四、JAVA的碼力不足,1008拿JAVA寫不動╮(╯_╰)╭