AC大美..之前一直WA到死 把search部分做成函数就AC了 实在不知道哪错了回头再看..
动态规划能不用递归就不用 循环从底层开始算到Jimmy落脚点那一层
[c]
#include <cstdio>
#include <cstdlib>
typedef struct flat {
int l,r,h,lmin,rmin;
} Flat;
Flat a[1001];
int N,MAX;
void search(int i,int k,bool bLeft);
int compare(const void *a,const void *b);
int main() {
int i,j,location;
int t,X,Y;
scanf("%d",&t);
while(t–) {
scanf("%d%d%d%d",&N,&X,&Y,&MAX);
for(i=1;i<=N;i++)
scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].h);
qsort(a+1,N,sizeof(a[0]),compare);
for(i=1;i<=N+1;i++) {
if(a[i].l<=X&&a[i].r>=X||i==N+1) {
a[i-1].l=a[i-1].r=X;
a[i-1].h=Y;
location=i-1;
break;
}
}
for(i=N;i>=location;i–) {
for(j=i+1;j<=N;j++)
if(a[j].h!=a[i].h)
break;
search(i,j,true);
search(i,j,false);
}
printf("%d\n",a[location].lmin);
}
return 0;
}
void search(int i,int k,bool bLeft) {
int x,*min,gotol,gotor,fall;
if(bLeft) {
x=a[i].l;
min=&a[i].lmin;
}
else {
x=a[i].r;
min=&a[i].rmin;
}
for(;k<=N;k++)
if(a[k].l<=x&&a[k].r>=x)
break;
if(k==N+1)
if(a[i].h>MAX)
*min=-1;
else
*min=a[i].h;
else {
fall=a[i].h-a[k].h;
if(fall>MAX)
*min=-1;
else {
gotol=fall+x-a[k].l+a[k].lmin;
gotor=fall+a[k].r-x+a[k].rmin;
if(a[k].lmin==-1)
if(a[k].rmin==-1)
*min=-1;
else
*min=gotor;
else
if(a[k].rmin==-1)
*min=gotol;
else
if(gotol<gotor)
*min=gotol;
else
*min=gotor;
}
}
}
int compare(const void *a,const void *b) {
return ((Flat *)b)->h-((Flat *)a)->h;
}
[/c]
References:
Legiano Casino Spiele https://invent.kde.org/-/external_redirect?url=https://bybio.co/brenthzl7
References:
Legiano Casino Login https://www.kaskus.co.id/
References:
Legiano Casino Zahlungsmethoden clients1.google.ng
References:
Legiano Online Casino http://skin-skin5–shop2.socksappeal.cafe24.com/member/login.html?returnUrl=https://ksk-kansk.ru/bitrix/redirect.php?goto=https://de.trustpilot.com/review/der-wikinger-shop.de
References:
Legiano Casino Sicherheit thesamba.com
References:
Legiano Casino sicher http://images.google.com.hk/url?q=https://bravo.astroempires.com/redirect.aspx?https://de.trustpilot.com/review/beyondjewellery.de
References:
Legiano Casino Anmelden maps.google.com.ai
References:
Legiano Casino Live Casino https://alltrack.org/go/http:/es.yoo7.com/go/aHR0cHM6Ly9kZS50cnVzdHBpbG90LmNvbS9yZXZpZXcvZGVyLXdpa2luZ2VyLXNob3AuZGU
References:
Legiano Casino legal http://podvodny.ru/bitrix/redirect.php?goto=https://vnn.bio/georgiana2
References:
KingMaker Casino Einzahlung per Giropay 301.tv
References:
KingMaker Casino Willkommensbonus Einzahlung https://bybio.co/
References:
KingMaker Casino Einzahlungsbonus 100% heres.link
References:
Kingmaker Casino Auszahlung https://biolink.website/
References:
KingMaker Casino Einzahlung mit Klarna https://m.anwap.love/go_url.php?r=http://de.trustpilot.com/review/beyondjewellery.de
References:
KingMaker Casino Ersteinzahlungsbonus http://images.google.com.gt
References:
KingMaker Casino Bonus mit Einzahlung https://owner.netkeiba.com
References:
KingMaker bonus aktivieren http://www.google.gg/url?sa=t&url=https://de.trustpilot.com/review/beyondjewellery.de
References:
KingMaker vip bonus http://images.google.gy
References:
KingMaker Casino Einzahlung und Freispiele http://www.dsl.sk/article_forum.php?action=reply&forum=255549&entry_id=147673&url=https://de.trustpilot.com/review/beyondjewellery.de
References:
Kingmaker Casino Promo Code https://m.sogou.com/web/searchList.jsp?&sosojump=1&pid=sogou-misc-77c493ec14246d74&keyword=bybio.co/johnarnott
References:
Kingmaker casino bitcoin einzahlung https://forums-archive.eveonline.com/warning/?l=https://tinyurl.ee/genevievenugen&domain=tunningn.ir
References:
KingMaker Casino Freispiele bei Einzahlung https://galaxy.click/outgoing?url=https://bybio.co/xvuhermine
References:
Legiano Casino Video Review sculptandpaint.com
References:
KingMaker Casino Einzahlungsbonus http://images.google.md/url?q=https://3scomputers.com/mckinleyschrod
References:
Legiano Casino Alternative http://clients1.google.vg/url?q=https://telegra.ph/Offizielle-Seite-Deutschland-06-07-2
References:
KingMaker willkommensbonus einzahlung http://maps.google.de/url?sa=t&url=https://yuklink.me/clqkristofer94
References:
Legiano Casino Paysafecard http://forum.zidoo.tv/proxy.php?link=https://earthwiki.space/wiki/Bonus_Spiele_Zahlungen_in_sterreich
References:
Legiano Casino Jackpot maps.google.ee
References:
Legiano Casino Verifizierung http://portal.novo-sibirsk.ru
References:
Legiano Casino Gutscheincode http://image.google.com.tn/
References:
Legiano Casino Treueprogramm community.playstarbound.com
References:
KingMaker einzahlungsmethoden http://cse.google.co.je/
References:
Legiano Casino Spielen http://toolbarqueries.google.ml/url?q=https://telegra.ph/Offizielle-Schweizer-Seite-06-07
References:
KingMaker mobile casino echtgeld http://image.google.by/
References:
Kingmaker Casino Auszahlung http://maps.google.com.co/url?q=https://de2wa.com/aishayhd428129
References:
Kingmaker casino anmelden einzahlung htcdev.com
References:
KingMaker Casino Einzahlung sofort toolbarqueries.google.je
References:
Legiano Casino Anmelden http://images.google.com.pe/
References:
Monro Casino Österreich link.avito.ru
References:
Hitnspin willkommensbonus https://dev.thep.lu.se
References:
Hit’n spin casino http://prod-dbpedia.inria.fr
References:
Monro Casino Lizenz http://www.google.com.hk/
References:
Hitnspin casino zahlungsmethoden https://ok.ru/dk?cmd=logExternal&st.name=externalLinkRedirect&st.link=https://illustrators.ru/away?link=http://de.trustpilot.com/review/der-wikinger-shop.de
References:
Hitnspin casino paysafecard https://aktsh.ru
References:
Hitnspin casino app http://maps.google.com.tr
References:
Hitnspin casino auszahlungslimit http://www25.ownskin.com
References:
Hitnspin casino bonuscode shemalefucksguy.allxxxtgp.com
References:
Hitnspin casino echtgeld https://www.ecocitycraft.com/
References:
Hitnspin casino no deposit bonus http://kimberly-club.ru/bitrix/redirect.php?event1=&event2=&event3=&goto=https://www.rosewood.edu.na/profile/papeeeffarmer11161/profile
References:
Hit n spin bewertung https://tabletennis.businesschampions.ru/