PAT Public Bike Management

Source: Internet
Author: User

Public Bike Management

More complex to enter. My idea was to do it directly with a DFS recursive backtracking

The key is that test instructions is also more fuzzy attention points as follows

1. The way to go can be adjusted, come back not adjustable

2. Shortest Path

3. Meet 2 and send out the least car

4. Meet 3 and bring back the fewest cars

The AC code is as follows

1#include <stdio.h>2#include <stdlib.h>3 #defineMAX 10000004 intc,n,sp,m;5 intg[501][501];6 intflag[501];7 intweight[501];8 intpath[501];9 intpath1[501];Ten intCurdis,curbike,cursend; One intDis,bike=max,mindis=max,minsend=MAX; A intflag1,k=0; - voidDfsintv) - { the     inti,j=1; -      -     if(dis>Mindis) -         return; +path[k]=v; -     if(v==Sp) +     {     A         intflag1=0; at         if(mindis>dis) -flag1=1; -         Else if(dis==Mindis) -         { -             if(cursend<minsend) -flag1=1; in             Else if(cursend==minsend) -             { to                 if(curbike<bike) +flag1=1; -             } the         } *         if(FLAG1) $         {Panax Notoginseng              while(path1[j]!=0) -             { thepath1[j]=0; +J + +; A             } thej=1; +              while(path[j]!=0) -             { $path1[j]=Path[j]; $J + +; -             } -mindis=dis; theMinsend=Cursend; -Bike=Curbike;Wuyi         } the         return; -     } Wu      -flag[v]=1; About      for(i=1; i<=n;i++) $     {     -         if(flag[i]!=1&&g[v][i]>0) -         {         -dis+=G[v][i]; A             intLastcurbike=Curbike; +             intLastcursend=Cursend; the              -             if(weight[i]+curbike<c/2) $             { thecursend+=c/2-(weight[i]+curbike); theCurbike=0; the             } the             Else -curbike=weight[i]+curbike-c/2; ink++; thepath[k]=v; the DFS (i);  Aboutpath[k]=0;  thek--;  theflag[i]=0; theCursend=Lastcursend; +Curbike=Lastcurbike; -dis-=G[v][i]; the                         Bayi         }     the     }     the } - intMain () - { the     inti,j=1, c1,c2,l; thescanf"%d%d%d%d",&c,&n,&sp,&M); the      for(i=1; i<=n;i++) thescanf"%d",&weight[i]); -      for(i=1; i<=m;i++) the     { thescanf"%d%d%d",&c1,&c2,&L); theg[c1][c2]=g[c2][c1]=L;94     } theDfs0); theprintf"%d 0", minsend); the      while(path1[j]!=0)98     { Aboutprintf"->%d", Path1[j]); -J + +;101     }102printf"%d\n", bike);103}

PAT Public Bike Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.