| ||||||||||
| 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 | |||||||||
无法WA对待测试数据都能给出正确答案。
包括:
64
40 40 30 35 35 26 15 40 40 40 40 40 40 40 40 40 40 40 40
40 40 40 40 43 42 42 41 10 4 40 40 40 40 40 40 40 40 40
40 40 40 40 40 25 39 46 40 10 4 40 40 37 18 17 16 15 40
40 40 40 40 40 40
64
40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 43 42 42 41 10 4 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40
6
8 3 5 7 7 2
0
都是瞬间给出,没有使用排序。 以下是代码,虽然没AC,暂时放下了。
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <set>
using namespace std;
#define MAX_UN 51
int count_s[MAX_UN];
int count[MAX_UN];
set<int> canot;
#define save_count() memcpy(count_s,count,sizeof(int)*MAX_UN )
#define recove_cout() memcpy(count,count_s,sizeof(int)*MAX_UN )
bool search(int val)
{
//printf("s:%d\n",val);
if (canot.find(val)!=canot.end() )
return false;
if (val<MAX_UN)
{
if (count[val]>0)
{
count[val]--;
return true;
}
}
for (int i=val-1; i >=1 ; i-- )
{
if (i<MAX_UN && count[i]>0 )
{
count[i]--;
if( search(val-i)==true ) return true;
count[i]++;
}
}
canot.insert(val);
return false;
}
int main()
{
int n;
while ( cin>>n )
{
if (n==0)
break;
int i=0;
int sum=0;
int val;
int max=-1;
memset(count,0, sizeof(int)* MAX_UN );
while ( i<n )
{
cin>>val ;
if ( val>max )
max=val;
count[ val ]++;
sum += val ;
i++;
}
save_count();
int len;
int ret=sum;
for ( i=max; i<=sum ; i++)
{
if ( sum%i!=0 )
continue;
/*
printf(" %d\n",i);
if (i==834)
{
printf("xx");
}
*/
recove_cout();
canot.clear();
bool status=true;
len=sum/i;
for ( int j=0;j< len;j++ )
{
if (search(i)!=true )
{
status=false;
break;
}
}
if (status==true)
{
ret=i;
break;
}
}
cout<<ret<<endl;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator