思路是board上的.. 经常是不看board没法做啊
思路非常牛B, 来自board上的apunix同学
用BFS,首先设墙和题目已给的路径上的所有点为used,剩余点为unused,然后利用BFS算出从起点到除墙以外的那些点的最短距离,然后利用BFS算出从终点到除墙以外的那些点的最短距离。
(1)判断最短路径是否唯一
如果不唯一,对于那些unused的点,必存在一个点,从起点到这点的最短距离加上从终点到这点的最短距离等于题目给出的最短距离长度
(2)判断墙是否多余
检查题目给出的墙分隔的那些点对,对一个一个被墙分隔的点对(a1,b1),(a2,b2),如果分隔它们的墙是多余的,那么从起点到(a1,b1)的最短距离加上从终点到(a2,b2)的最短距离必大于题目给出的最短距离长度pathlen,且从起点到(a2,b2)的最短距离加上从终点到(a1,b1)的最短距离也必大于pathlen,也就是起点,(a1,b1),(a2,b2),终点不可能在一个最短路径上,也就没必要用墙分隔了
一个小逻辑 有墙多余<=>存在一个墙多余
如果有m个墙是多余的,那么只考虑拿掉这m个墙中的一个其他m-1不动, 这个墙还是多余的, 因为路线完全没有依靠它
我犯了个错误.. 我以为终点一定在[w-1][h-1], 还有有人把每个点到终点/起点的距离初始化为-1, 那么如果有一个区域是封闭的会容易出错.
我是初始化为2E9, 继而中间想到的一个细节是, 这里没问题, 以后如果这些表示正无限的数相加 会超出int表示范围变成负的.. 要小心
代码:
[cpp]#include <iostream>
typedef struct orz {
int d[2]; ///d[0] for distance from start, d[1] for d to end;
bool way;
bool on;
bool s,w; ///if there’s a wall on the south/west of this unit;
} Orz;
Orz a[100][100];
int w,h;
void dij(int o) {
bool end;
end=false;
while(!end) {
end=true;
for(int i=0;i<w;i++)
for(int j=0;j<h;j++) {
if(!a[i][j].on)
continue;
end=false;
if( i-1>=0 && (!a[i][j].w) && a[i][j].d[o]+1<a[i-1][j].d[o]) {
a[i-1][j].d[o]=a[i][j].d[o]+1;
a[i-1][j].on=true;
}
if( j-1>=0 && (!a[i][j].s) && a[i][j].d[o]+1<a[i][j-1].d[o]) {
a[i][j-1].d[o]=a[i][j].d[o]+1;
a[i][j-1].on=true;
}
if( i+1<w && (!a[i+1][j].w) && a[i][j].d[o]+1<a[i+1][j].d[o]) {
a[i+1][j].d[o]=a[i][j].d[o]+1;
a[i+1][j].on=true;
}
if( j+1<h && (!a[i][j+1].s) && a[i][j].d[o]+1<a[i][j+1].d[o]) {
a[i][j+1].d[o]=a[i][j].d[o]+1;
a[i][j+1].on=true;
}
a[i][j].on=false;
}
}
return;
}
int main () {
int t,n,x1,y1,x2,y2,xa,ya,endx,endy;
int wayx,wayy,wayd,wayd_min;
char go;
bool ok;
Orz init;
init.d[0]=init.d[1]=(int)2E9;
init.way=init.on=false;
init.s=init.w=false;
scanf("%d",&t);
while(t–) {
scanf("%d%d",&w,&h);
while(getchar()!=’\n’);
for(int i=0;i<w;i++)
for(int j=0;j<h;j++)
a[i][j]=init;
wayx=wayy=0;
a[0][0].way=true;
wayd=0;
while((go=getchar())!=’\n’) {
wayd++;
switch(go) {
case ‘R’:
wayx++;
break;
case ‘L’:
wayx–;
break;
case ‘U’:
wayy++;
break;
case ‘D’:
wayy–;
}
a[wayx][wayy].way=true;
}
endx=wayx;
endy=wayy;
scanf("%d",&n); //n: num of walls
for(int i=0;i<n;i++) {
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1>x2||y1>y2) {
xa=x1;
ya=y1;
}
else {
xa=x2;
ya=y2;
}
if(x1==x2)
a[xa][ya].s=true;
else
a[xa][ya].w=true;
}
/*
for(int i=0;i<w;i++) {
for(int j=h-1;j>=0;j–) {
if(a[i][j].w)
printf("|");
else
printf(" ");
if(a[i][j].way)
printf("@");
if(a[i][j].s)
printf("___\t");
else
printf(" \t");
}
printf("\n");
} */
a[0][0].on=true;
a[0][0].d[0]=0;
dij(0);
for(int i=0;i<w;i++)
for(int j=0;j<h;j++)
a[i][j].on=false;
a[endx][endy].on=true;
a[endx][endy].d[1]=0;
dij(1);
ok=true;
wayd_min=a[0][0].d[1];
if(wayd_min!=wayd)
ok=false;
if(ok)
for(int i=0;i<w;i++)
for(int j=0;j<h;j++) {
if(a[i][j].way)
continue;
if(a[i][j].d[0]+a[i][j].d[1]<=wayd_min) {
ok=false;
i=w;
break;
}
}
if(ok)
for(int i=1;i<w;i++)
for(int j=0;j<h;j++) {
if(!a[i][j].w)
continue;
if( a[i][j].d[0]+1+a[i-1][j].d[1]>wayd_min
&& a[i][j].d[1]+1+a[i-1][j].d[0]>wayd_min) {
ok=false;
i=w;
break;
}
}
if(ok)
for(int i=0;i<w;i++)
for(int j=1;j<h;j++) {
if(!a[i][j].s)
continue;
if( a[i][j].d[0]+1+a[i][j-1].d[1]>wayd_min
&& a[i][j].d[1]+1+a[i][j-1].d[0]>wayd_min) {
ok=false;
i=w;
break;
}
}
if(ok)
printf("CORRECT\n");
else
printf("INCORRECT\n");
}
return 0;
}[/cpp]
References:
Legiano Casino Kritik mineland.net
References:
Ligiano Casino https://www.rmnt.ru
References:
Kingmaker casino einzahlungsbonus code 2026 https://bion.ly
References:
KingMaker Casino Einzahlung mit Bitcoin voffice.lawyers.bh
References:
KingMaker Casino Einzahlungsbonus ohne Umsatzbedingungen mylinkbox.me
References:
KingMaker Casino Gewinne auszahlen lassen https://qr.dsd.edu.gh/
References:
Kingmaker casino paysafecard einzahlung http://images.google.com.ec/url?q=https://de.trustpilot.com/review/beyondjewellery.de
References:
Kingmaker casino einzahlen http://cse.google.com.nf/url?q=https://de.trustpilot.com/review/beyondjewellery.de
References:
KingMaker einzahlung google pay https://www.camangels.com/
References:
Legiano Casino Auszahlung app.salesloft.com
References:
Legiano Casino Live Casino http://images.google.com.sg/url?sa=t&url=http://graph.org/Legiano-Casino-Ehrliche-Bewertung-2026-Neuer-Bonus-06-07
References:
Legiano Casino Jackpot http://cse.google.co.zw/url?sa=t&url=http://sibze.ru/index.php?subaction=userinfo&user=ugandacan80
References:
Legiano Casino Live Casino http://images.google.com.sa
References:
Kingmaker Casino Bonus http://fr.thefreedictionary.com
References:
Legiano Casino Verifizierung images.google.com.vc
References:
KingMaker Casino Ersteinzahlungsbonus images.google.cf
References:
KingMaker Casino Einzahlung mit Bankeinzug http://cse.google.lk/url?sa=i&url=https://mssq.me/lucienne32
References:
KingMaker Casino Einzahlung per Bitcoin http://www.google.ca/
References:
Kingmaker Casino Kundenservice http://maps.google.ng
References:
Legiano Casino Bonus ohne Einzahlung https://wiki.opencellid.org/api.php?action=https://telegra.ph/Legiano-Casino-Test-2026-Willkommenspaket-von-bis-zu-500-06-07
References:
KingMaker Casino Neukundenbonus Einzahlung http://images.google.nr/url?q=https://smartbusinesscards.in/roccoorozco53
References:
KingMaker Casino Freispiele bei Einzahlung translate.itsc.cuhk.edu.hk
References:
Legiano Casino Betrug alt1.toolbarqueries.google.com.nf
References:
KingMaker Casino Einzahlung per Sofortüberweisung yandex.ru
References:
Legiano Casino iPhone maps.google.com.br
References:
Legiano Casino Zahlungsmethoden cse.google.sk
References:
KingMaker einzahlung freispiele http://maps.google.co.jp/url?q=https://liy.ke/eleanorelipsey
References:
Kingmaker Casino einloggen https://shop-photo.ru
References:
Legiano Casino Auszahlung http://podvodny.ru/bitrix/rk.php?goto=https://drake-jakobsen-2.thoughtlanes.net/legiano-casino-test-modernes-online-casino-deutschland
References:
Hitnspin online casino backlink.scandwap.xtgem.com
References:
Monro Casino Kundenservice http://podvodny.ru/bitrix/redirect.php?goto=https://biolink.website/carminefar
References:
Hitnspin casino mit echtgeld http://maps.google.dj/url?sa=t&url=https://sc.news.gov.hk/TuniS/de.trustpilot.com/review/der-wikinger-shop.de/
References:
Hitnspin casino aktionscode https://www.avensis-forum.de/proxy.php?link=https://gitlab.com/-/external_redirect?url=https://de.trustpilot.com/review/der-wikinger-shop.de
References:
Hitnspin casino seriös https://epsilon.astroempires.com/redirect.aspx?https://mcpedl.com/leaving/?url=http://de.trustpilot.com/review/der-wikinger-shop.de
References:
Monro Casino Gutscheincode tonelib.net
References:
Hit n spin casino deutsch http://dreamwar.ru/redirect.php?https://vocab.getty.edu/resource?uri=https://de.trustpilot.com/review/der-wikinger-shop.de
References:
Hitnspin verifizierung https://forum.mds.ru/
References:
Hitnspin online casino semanticmarker.com
References:
Hitnspin casino live spiele http://maps.google.com.ai/url?q=http://cr.naver.com/redirect-notification?u=http://de.trustpilot.com/review/der-wikinger-shop.de
References:
Hitnspin deutschland images.google.cf
References:
Hitnspin casino live https://jugem.jp
References:
Hit’n’spin casino 25 euro code https://www.rmnt.ru/go.php?url=bookmarkdaily.site/item/hitnspin-casino-bewertung-alle-infos-zur-spielhalle
References:
Hitnspin bonus eda.europa.eu
References:
Hitnspin casino auszahlungsdauer https://www.euromonitor.com/
References:
Hitspin casino winehq.org.ru
References:
Hitnspin casino bonuscode camtubechat.com
References:
Hit’n’spin casino 50 free spins http://wiki.s-classclinic.com/
References:
Hitnspin casino bonus ohne einzahlung https://litsovet.ru:443/away/?url=https://readeach.com/ilaguertin070
References:
Lollybet Casino https://www.omicsonline.org/
References:
Lollybet Einzahlung http://kimberly-club.ru/bitrix/redirect.php?event1=&event2=&event3=&goto=https://jovita.com/charlafogle007