Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:我有一个猜想,不知道用来做这道题对不对

Posted by outman at 2012-07-26 13:29:39 on Problem 1011
In Reply To:我有一个猜想,不知道用来做这道题对不对 Posted by:pheonix2012 at 2012-07-06 17:26:45
> 我有一个猜想:对于一个数列(也就是我们输入的n个数据)a1,a2,a3...an,记其最大值为a(max),其和为s;
> s的约数记为s1,s2,s3...sn;记s(t)为a(max)<=s(t)<s(t+1);若s(t)可以化为a(max)+a(x)的形式(x为任意值)或s(t)=a(max);那么s(t)就是所求值;否则所求值为s.
> 不知有没有牛人能证明或否定我的猜想
> 贴代码,机试数据貌似无误,但是一直WA,求牛人指教
> #include<iostream>
> using namespace std;
> int compare(const void *a,const void *b)
> {return *((int *)a)-*((int *)b);}
> int main()
> {int i,p,q,s=0,t,r,max,sum=0,a[64],b[3000];
> while(cin>>t)
> 	{if(t==0)
> 	break;
> 	else
> 	for(i=0;i<t;i++)
> 		{cin>>a[i];
>          sum+=a[i];}
> max=a[0];
> for(i=0;i<t;i++)
> 	{if(max<a[i])
> 	swap(a[i],max);}
>       for(p=sum;p>=max;p--)//记录输入数的和的大于等于max的约数在b[n]中,s记录这样的数有多少个
> 		  {if(sum%p==0)
> 		 {b[s]=p;
> 	   s++;}}		  
> 	  qsort(b,s,sizeof(int),compare);//把b[n]排下
> 	   for(q=0;q<s;q++)
> 	  {if(b[q]==max)//先看看约数中最小的是不是就是max,是的话就是答案
> 		  {cout<<max<<endl;
> 	  goto end;}
> 	  else
> 	  for(i=0;i<t;i++)
> 		  {if(a[i]+max==b[q])//再看看有没有max+a[i]==某个约数
> 			  {cout<<b[q]<<endl;
> 	 goto end;}
> 	  }}
> 	  cout<<sum<<endl;//都没有的话,答案就是输入数之和
>       end:sum=0,s=0;}
> 	  return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator