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:把数按整数存了仍然WA,哪个高手能在给一组BT点的数据啊?

Posted by LiZhiXu at 2006-09-27 19:46:05 on Problem 1064
In Reply To:把数按整数存了仍然WA,哪个高手能在给一组BT点的数据啊? Posted by:albertmn at 2006-09-27 16:58:18
> #include<iostream.h>
> #include<stdio.h>
> #include<math.h>
> 
> const int Scope_Exceed=0;
> const int Meet=1;
> const int Larger=2;
> const int Smaller=3;
> int Constrain(long int length,long int *s);
> double SearchLength(long int lscope,long int uscope,long int *s);
> 
> int N,K;
> void main()
> {
> 	long int *Stock,sum=0,lscope=1,uscope,min=10000000;
> 	double input;
> 
> 	scanf("%d %d",&N,&K);
> 	Stock=new long int[N];
> 	for(int i=0;i<N;i++)
> 	{
> 		cin>>input;//---------------->不要用double,用整数读
> 
> 		Stock[i]=(long int)(100*input);
> 		if(Stock[i]<min)
> 			min=Stock[i];
> 
> 		sum+=Stock[i];
> 	}
> 
> 	uscope=min;
> 
> 	SearchLength(lscope,uscope,Stock);
> 	printf("%.2f\n",SearchLength(lscope,uscope,Stock));
> }
> 
> int Constrain(long int length,long int *s)
> {
> 	int sum=0;
> 
> 	for(int i=0;i<N;i++)
> 	{
> 		sum+=(int)(s[i]/length);
> 	}
> 
> 	if(sum==K)
> 		return Meet;
> 	else if(sum<K)
> 		return Larger;
> 	else
> 		return Smaller;
> }
> 
> double SearchLength(long int lscope,long int uscope,long int *s)
> {
> 	int l,u,m;
> 	double res=0;
> 
> 	l=lscope;
> 	u=uscope;
> 
> 	while(l<=u)
> 	{
> 		m=(l+u)/2;
> 
> 		switch(Constrain(m,s))
> 		{
> 		case Meet:
> 			res=m;
> 			l=m+1;
> 			break;
> 		case Larger:
> 			u=m-1;
> 			break;
> 		case Smaller:
> 			res=m;
> 			l=m+1;
> 			break;
> 		default:break;
> 		}
> 	}
> 
> 	return (double)res/100;
> }

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