acm 1011 Sticks
来源:互联网 发布:淘宝包邮券怎么设置 编辑:程序博客网 时间:2024/05/24 01:47
Sticks
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 113105 Accepted: 25961
Description
George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which computes the smallest possible original length of those sticks. All lengths expressed in units are integers greater than zero.
Input
The input contains blocks of 2 lines. The first line contains the number of sticks parts after cutting, there are at most 64 sticks. The second line contains the lengths of those parts separated by the space. The last line of the file contains zero.
Output
The output should 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
#include<iostream>#include <stdio.h> #include <stdlib.h>using namespace std;int num[64];bool mg[64];int n;int cmp(const void *i, const void *j){return *(int *)j - *(int *)i;}bool find(int m,int k,int len){ if(m==0 && k==0) return true; if(m==0) m=len; for(int i=0;i<n;i++) { if(!mg[i] && num[i]<=m) { mg[i]=true; if(find(m-num[i],k-1,len)) return true; mg[i]=false; if (m == num[i] || m == len) return false; } } return false;}int main(){ int i,max,sum; while(true) { scanf("%d",&n); if(n==0) break; max=0; sum=0; for(i=0;i<n;i++) { scanf("%d",&num[i]); sum=sum+num[i]; mg[i]=false; } qsort(num, n, sizeof(int), cmp); for(int j=num[0];j<=sum;j++) if((sum%j==0) && find(j,n,j)) { cout<<j<<endl; break; } } system("pause"); return 0;}
- PKU ACM 1011 Sticks
- acm 1011 Sticks
- PKU ACM 1011 Sticks
- ACM —— 1011 Sticks
- ACM 1011 Sticks (研究中。。。)
- ACM-HDU1051-Wooden Sticks
- [ACM] hdu 1051 Wooden Sticks
- ACM--steps--4.3.5--Sticks
- HDU ACM 1051 Wooden Sticks
- HDU ACM 1051 Wooden Sticks
- 2016ACM暑假集训 - Sticks
- 杭电acm Wooden Sticks
- 1011 Sticks
- 1011 Sticks
- 1011--Sticks
- 1011 Sticks
- ACM-DFS之Sticks——hdu1455
- poj 1011-sticks
- JAVA学习.方法的重载的理解
- 黑马程序员——注解
- UVA11361 递推关系
- 挂载点
- CoreImage的使用及常见滤镜工具(一)
- acm 1011 Sticks
- make_shared() shared_prt()详解区别
- 下载Linux镜像的好地方
- css的效率和浏览器渲染的速度
- 冒泡排序(BubbleSort)
- 编写设计一个People(人)类。该类的数据成员有年龄(age)、身高(height)、体重(weight)和人数(num),其中人数为静态数据成员
- STL中迭代器
- 给Ubuntu安装Windows的字体
- 定义一个描述学生(Student)基本情况的类,数据成员包括姓名(name)、学号(num)、数学成绩(mathScore)、英语成绩(englishScore)、人数(count)、数学总成绩(ma