拯救ice-cream(Vijos p1340)
2012-10-05 22:04
405 查看
今晚我和几个哥们一起编这道坑爹的搜索题,BFS,刚开始总是溢出,绞尽脑汁想了各种优化办法。
刚开始直接用bool判重,后来发现这样判重可能会漏掉最优解。拿了水出来的60分后,没编了,王大牛还在奋斗,我们商讨了一下判重方法,用一个记录,记录目前到这点的最短时间,这样就可以避免漏掉最优解的情况,以下是借用王大牛的程序:
大概就是BFS,然后判重,没什么别的技巧,憋了几个小时总算是憋出了100分,惭愧啊惭愧!
By ZYT
12.10.05
刚开始直接用bool判重,后来发现这样判重可能会漏掉最优解。拿了水出来的60分后,没编了,王大牛还在奋斗,我们商讨了一下判重方法,用一个记录,记录目前到这点的最短时间,这样就可以避免漏掉最优解的情况,以下是借用王大牛的程序:
program P1340; type rec=record x,y:longint; di:longint; time:longint; end; var s:array[1..100000,1..4] of longint; time:array[1..30,1..30] of longint; a:array[1..30,1..30] of char; sb1,sb2:char; b:array[1..30,1..30] of longint; q,open,closed,t,x,y,x0,y0,x1,y1,i,j,k,l,m:longint; begin q:=maxlongint; assign(input,'haha.in'); reset(input); readln(t); read(x,y); for j:=1 to y do begin read(sb1,sb2); for i:=1 to x do begin read(a[i,j]); if a[i,j]='.'then b[i,j]:=1 else if a[i,j]='#'then b[i,j]:=2 else if a[i,j]='o' then b[i,j]:=maxlongint else if a[i,j]='s' then begin x0:=i;y0:=j; b[i,j]:=1;end else if a[i,j]='m' then begin x1:=i;y1:=j; b[i,j]:=0;end; end; end; close(input); for j:=1 to y do for i:=1 to x do time[i,j]:=maxlongint; closed:=0; open:=1; s[1,1]:=x0; s[1,2]:=y0; s[1,3]:=0; s[1,4]:=0; repeat repeat inc(closed); if time[s[closed,1],s[closed,2]]>s[closed,4] then begin time[s[closed,1],s[closed,2]]:=s[closed,4]; if (s[closed,3]<>1)and(s[closed,1]<x)and(a[s[closed,1]+1,s[closed,2]]<>'o')then begin inc(open); s[open,1]:=s[closed,1]+1; s[open,2]:=s[closed,2]; s[open,3]:=3; s[open,4]:=s[closed,4]+b[s[closed,1],s[closed,2]]; end; if a[s[open,1],s[open,2]]='m' then break; if (s[closed,3]<>3)and(s[closed,1]>1)and(a[s[closed,1]-1,s[closed,2]]<>'o') then begin inc(open); s[open,1]:=s[closed,1]-1; s[open,2]:=s[closed,2]; s[open,3]:=1; s[open,4]:=s[closed,4]+b[s[closed,1],s[closed,2]]; end; if a[s[open,1],s[open,2]]='m' then break; if (s[closed,3]<>0)and(s[closed,2]>1)and(a[s[closed,1],s[closed,2]-1]<>'o') then begin inc(open); s[open,1]:=s[closed,1]; s[open,2]:=s[closed,2]-1; s[open,3]:=2; s[open,4]:=s[closed,4]+b[s[closed,1],s[closed,2]]; end; if a[s[open,1],s[open,2]]='m' then break; if (s[closed,3]<>2)and(s[closed,2]<y)and(a[s[closed,1],s[closed,2]+1]<>'o') then begin inc(open); s[open,1]:=s[closed,1]; s[open,2]:=s[closed,2]+1; s[open,3]:=0; s[open,4]:=s[closed,4]+b[s[closed,1],s[closed,2]]; end; if a[s[open,1],s[open,2]]='m' then break; end; until (a[s[open,1],s[open,2]]='m')or(closed=open); if q>s[open,4] then q:=s[open,4]; until (closed=open); if q>=t then write('55555') else write(q); end.
大概就是BFS,然后判重,没什么别的技巧,憋了几个小时总算是憋出了100分,惭愧啊惭愧!
By ZYT
12.10.05
相关文章推荐
- 拯救ice-cream(广搜+优先级队列)
- TYVJ 1117 拯救ice-cream 解题报告
- 分糖果 && 拯救ice-cream(tyvj 1083 && 1117)
- tyvj1117拯救ice-cream&&nyoj284坦克大战
- 深度优先搜索之拯救ice-cream
- vijos p1340(拯救ice-cream)
- P1117 拯救ice-cream tyvj
- 【搜索】拯救ice-cream
- |Tyvj|BFS|P1117 拯救ice-cream
- tyvj P1117 拯救ice-cream
- tyvj1117 拯救ice-cream
- 拯救ice-cream
- hdu2121 Ice_cream’s world II 【不定根的最小树形图】
- 转载:Introducing the software testing ice-cream cone (anti-pattern)
- kuangbin专题八 HDU2121 Ice_cream’s world II(不定根的最小树形图)
- Android 4.0 Ice Cream Sandwich Tablet 平板全方位屏幕截图
- CyanogenMod | Android Community Rom based on Ice Cream Sandwich
- hdu 2121 Ice_cream’s world II(不定根的最小树形图)
- Hud 2120 Ice_cream's world I[并查集]
- How to Implement Bluetooth Low Energy (BLE) in Ice Cream Sandwich