| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
超时,极度郁闷中!!!有谁帮看看!#include <stdio.h>
#include <iostream.h>
#include <fstream.h>
#include <memory.h>
#include <stdlib.h>
#define SIZE 300
int compare(const void *arg1,const void *arg2)
{
long a=*(long *)arg1;
long b=*(long *)arg2;
return b-a;
}
main (void)
{
#ifndef ONLINE_JUDGE
freopen ("Sticts.txt","r",stdin);
#endif
long i,count;
long sum,max;
bool suc;
long array[SIZE],stack[SIZE],tos,av,left;
bool get[SIZE];
long st_num,current;
while (true)
{
scanf ("%d",&st_num);
if (st_num == 0)
{
break;
}
sum = 0;
max = 0;
for (i = 0;i < st_num;i++)
{
scanf ("%d",&array[i]);
sum += array[i];
if (array[i] > max)
{
max = array[i];
}
}
qsort(array,st_num,sizeof(long),compare);
for (i = max,suc = true;i <= sum && suc;i++)
{
if (sum % i == 0)
{
av = i;
count = sum / i;
memset (get,true,sizeof(get));
tos = -1;
left = av;
current = 0;
while (count > 1)
{
while (current < st_num && count > 1)
{
if (get[current] && left >= array[current] )
{
left -= array[current];
if (left == 0)
{
count--;
left = av;
current = 0;
}
get[current] = false;
stack[++tos] = current;
}
current++;
}
if (count <= 1)
{
break;
}
if (tos != -1)
{
current = stack[tos--];
get[current] = true;
left += array[current++];
if (left > av)
{
left -= av;
count++;
}
}
else
{
break;
}
}
if (count <= 1)
{
cout << i << "\n";
suc = false;
break;
}
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator