POJ 2718 Smallest difference (brute force enumeration) (greedy to add)

Source: Internet
Author: User

ABS written fabs led WA to a pitch.

About Next_permutation () the basic application of the function in STL

Http://www.cnblogs.com/luosuo10/p/5479188.html

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cmath>6 using namespacestd;7 intt,n,a,b;8 inta[ -];9 Chars[ -];Ten Const intinf=0x3f3f3f; One voidinput () A { -n=0; - gets (s); the     intlen=strlen (s); -  -      for(intI=0; i<len;i++) -     { +         if('0'<= S[i] && s[i] <='9') -         { +a[n++] = s[i]-'0'; A         } at     } -  - } - voidSolve () - { -     if(n==2) in     { -printf"%d\n", ABS (a[0]-a[1])); to         return ; +     } -  the     intMid= (n+1)/2; *     intans=inf; $      DoPanax Notoginseng     { -a=b=0; the         if(a[0]!=0&& a[mid]!=0) +         { A              for(intI=0; i<mid;i++) the             { +a=a*Ten+A[i]; -             } $              for(inti=mid;i<n;i++) $             { -b=b*Ten+A[i]; -             } the             intRes=max (A-B,B-A);//>=0 -ans=min (ans,res);Wuyi         } the  -} while(Next_permutation (a,a+n)); Wu  -  Aboutprintf"%d\n", ans); $ } - intMain () - { -scanf"%d",&T); A GetChar (); +      while(t--) the     { - input (); $ solve (); the     } the     return 0; the}

POJ 2718 Smallest difference (brute force enumeration) (greedy to add)

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.