Hduoj 1455 && UVA 243 e-sticks

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1455

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=243

UVA Opening Description:

307-sticks

Time limit:3.000 seconds

Hduoj Opening Description:

E-sticksTime limit:3000MS Memory Limit:0KB 64bit IO Format:%lld &%lluTitle Description: 

Description


 

George took sticks of the same length and cut them randomly until all parts became at most units long. Now he wants to return sticks to the original state, but he forgot what many sticks he had originally and how long they wer E originally. Him and design a program which computes the smallest possible original length of those sticks. All lengths expressed in units is integers greater than zero.

Input

The input file contains blocks of 2 lines. The first line contains the number of sticks parts after cutting. The second line contains the lengths of those parts separated by the space. The last line of the file contains zero.

Output

The output file contains the smallest possible length of original sticks, one per line.

Sample Input

95 2 1 5 2 1 5 2 141 2 3 40

Sample Output

65


Analysis:
UVA will tle, Hduoj AC



AC Code:
1#include <algorithm>2#include <cstring>3#include <cstdio>4#include <iostream>5 using namespacestd;6 7 Const intN = 1e4+Ten;8 intlen[n],sum,l,t;9 intUsed[n];Ten  One intcmpConst void*a,Const void*b) A { -      return*(int*) b-* (int*) A; - } the  - BOOLDFS (intMintLeft ) - //m is the remaining number of sticks, left for the currently stitching stick and the assumed length of the stick length L also missing - { +     if(M = =0&& left = =0) -         return true; +     if(left = =0)//I just finished the fight . Aleft =L; at      for(intI=0; i<t; i++) -     { -        if(!used[i] && len[i]<=Left ) -         { -             if(i>0)//If the former is not available, then the current is not available . -             { in                 if(!used[i-1] && len[i] = = len[i-1]) -                     Continue; to             } +Used[i] =1; -             if(DFS (M-1, left-Len[i])) the                 return true; *             Else $             {Panax NotoginsengUsed[i] =0; -                 if(Len[i] = = Left | |L) the                     return false; +             } A         } the     } +     return false; - } $  $ intMain () - { -      while(SCANF ("%d", &t) &&T) the{sum =0 ; -          for(intI=0; i<t;i++)Wuyi         { thescanf"%d",&len[i]); -sum = sum +Len[i]; Wu         } -         //sort (len,len+t,cmp); Sort Timeout AboutQsort (Len,t,sizeof(int), CMP);//sort from big to small $          for(L = len[0]; l<=sum/2; l++) -         { -             if(sum%L) -                 Continue; Amemset (Used,0,sizeof(used)); +             if(DFS (t,l)) the             { -printf"%d\n", L); $                  Break; the             } the         } the         if(l>sum/2) theprintf"%d\n", sum); -     } in     return 0; the}

Hduoj 1455 && UVA 243 e-sticks

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.