GCPC2014 C Bounty Hunter

Source: Internet
Author: User

Test instructions: Give you a set of points on a plane (x values are unequal), ask you to go from the leftmost to the far right (only in the order of x increments), and then from the far right to the leftmost (in descending order of x) ask you what the shortest distance is.

Problem-solving ideas: dp[i][j] means that one of the roads has reached the shortest distance I have another road at J.

Problem Solving Code:

1 //File name:c.1.cpp2 //Author:darkdream3 //Created time:2015 March 17 Tuesday 09:15 20 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long -  - using namespacestd; - intT,n; - structpoint{ in   intx, y; -}p[555]; to Doubledp[555][555]; + DoubleDisintAintb) - { the    returnsqrt1.0* (p[a].x-p[b].x) * (p[a].x-p[b].x) +1.0* (P[A].Y-P[B].Y) * (P[A].Y-p[b].y)); * } $ intMain () {Panax Notoginsengscanf"%d",&t); -      while(t--) the     { +scanf"%d",&n); A         for(inti =1; I <= N;i + +) the        { +scanf"%d%d",&p[i].x,&p[i].y); -        } $        if(n = =1) $        { -printf"%f",0.0); -          Continue; the        } -dp[2][1] = DIS (1,2);Wuyi         for(inti =2; i < N;i + +) the        { -dp[i+1][i] =100000000;  Wu            for(intj =1; J < I; J + +) -           { Aboutdp[i+1][J] = dp[i][j] + dis (i,i+1); $dp[i+1][i] = min (dp[i+1][I],DP[I][J] + dis (j,i+1)); -           } -        } -printf"%f\n", dp[n][n-1] + DIS (n/A1)); A     } +     return 0; the}
View Code

GCPC2014 C Bounty Hunter

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.