UV216 violence Enumeration Full array

Source: Internet
Author: User

The data range is small, the violent enumeration is all lined up.

main.cpp//uva216////Created by Fangpin on 15/3/8.//Copyright (c) 2015 Fangpin. All rights reserved.//#include <iostream> #include <algorithm> #include <cstring> #include <cmath    > #include <vector> #include <algorithm>using namespace std;struct point{int x, y; Point () =default;}; Double len (const point &a,const point &b) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));}    int main (int argc, const char * argv[]) {//Insert code here ... int n,ca=1;        while (scanf ("%d", &n), N) {vector<point> A;        Vector<int> b;        Vector<int> Lis;            for (int. i=0;i<n;++i) {point tem;            scanf ("%d%d", &tem.x,&tem.y);            A.push_back (TEM);        B.push_back (i);        } double ans=0;        Lis=b;        for (int i=0;i<a.size () -1;++i) {Ans+=len (a[i],a[i+1]); } while (Next_permutation (B.begin (), B.end ())) {Double tem=0;            for (int i=0;i<a.size () -1;++i) {Tem+=len (a[b[i]],a[b[i+1]]);                } if (Tem<ans) {ans=tem;            Lis=b;        }} puts ("**********************************************************");                printf ("Network #%d\n", ca++); For (int. i=0;i<a.size () -1;++i) {//printf ("Cable requirement to connect (%d,%d) to (%d,%d) is%lf feet.\n", a[            Lis[i]].x,a[lis[i]].y,a[lis[i+1]].x,a[lis[i+1]].y],len (a[lis[i]],a[lis[i+1])); cout<< "Cable requirement to connect (" <<int (a[lis[i]].x) << "," << Int (A[LIS[I]].Y) <&lt ;")            To ("<<int (a[lis[i+1]].x) <<", "<<int (A[LIS[I+1]].Y) <<") are ";            printf ("%.2f", Len (a[lis[i]],a[lis[i+1]) +16);        cout<< "feet.\n";        } cout<< "Number of feet of cable required is"; printf ("%.2f.\n", ans+ (n-1) *16);//puts ("**********************************************************"); } return 0;}


UV216 violence Enumeration Full array

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.