HDU 4824 two-tone travel quotient issue

Source: Internet
Author: User

Since the jump need 400, greater than in the fan lane in one lap, so should be as few as possible to jump the fan path, converted into a double travel business problems,

That is, starting from Zone 0 to the largest area, and then back to Zone 0, all intermediate points need to go to one

#include "stdio.h" #include "string.h" #include "math.h" #include "algorithm" using namespace std;struct node{int x, y;}    A[1010];int Abs (int a) {if (a<0) return-a; else return A;}    BOOL CMP (node A,node b) {if (a.x!=b.x) return a.x<b.x; else return a.y<b.y;}    int N;int inf=0x3f3f3f3f;int dis[1010][1010],dp[1010][1010];int cal (int i,int j) {int temp,mark;    Temp=0;    if (a[i].x!=a[j].x) temp+=abs (a[i].x-a[j].x) *400;    Mark=abs (A[I].Y-A[J].Y);    if (mark>180) Mark=360-mark;    Temp+=mark; return temp;}    void DP () {int i,j,temp;    DP[0][1]=DIS[0][1];        for (j=2;j<=n;j++) {for (i=0;i<j-1;i++) dp[i][j]=dp[i][j-1]+dis[j][j-1];            for (i=0;i<j-1;i++) {temp=dp[i][j-1]+dis[i][j];        if (Temp<dp[j-1][j]) dp[j-1][j]=temp; }} Dp[n][n]=dp[n-1][n]+dis[n-1][n];}    int main () {int i,j,t;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n); for (I=1; i<=n;i++) scanf ("%d%d", &a[i].x,&a[i].y);        a[0].x=a[0].y=0;        Sort (a,a+n+1,cmp);        for (i=0;i<=n;i++) for (j=0;j<=n;j++) dis[i][j]=cal (I,J);        Memset (Dp,inf,sizeof (DP));        DP ();    printf ("%d\n", dp[n][n]+10*n); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4824 two-tone travel quotient issue

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.